【问题标题】:SWIG JNI Interface with DLL and declarations only仅带有 DLL 和声明的 SWIG JNI 接口
【发布时间】:2012-05-10 19:49:48
【问题描述】:

我有想要通过 JNI 访问的本机函数声明 并且我拥有包含所有类声明的 DLL。

我没有完整的头文件及其依赖项,但我有 DLL 其中包含所有信息。

是否可以使用 SWIG 创建 JNI 接口 只有 DLL 和函数声明?

另见:SWIG CYGWIN DLL linking 这是一个非常相似的问题。

【问题讨论】:

    标签: dll header java-native-interface swig


    【解决方案1】:

    你不能这样做,除非你可以guess enough information from the DLL 能够重建一个(可能是部分的)头文件。

    它需要包含有关您关心的函数(不必是全部)和您关心的类型(不必是全部,但您需要知道每个函数的名称)的信息)。

    这样您就可以正常构建模块文件了。您可以根据它是 C++ 还是 C 来猜测/推断其中的一些信息 - 如果是 C++,则损坏的名称会告诉您大部分您需要知道的输入信息,而不是返回类型。


    作为我编译的例子:

    class foo {};
    
    foo *make_foo() { return new foo; }
    
    void eat_foo(foo*) {}
    
    void frobinate_two_foos(foo*,foo*) {}
    

    作为 DLL 使用:

    i58​​6-mingw32msvc-g++ -shared -Wall -Wextra original.cc -o test.dll

    从中我可以看到 DLL 中的符号:

    i58​​6-mingw32msvc-nm test.dll|i586-mingw32msvc-c++filt

    有趣的是:

    6bec1286 T frobinate_two_foos(foo*, foo*) 6bec1280 Teat_foo(foo*) 6bec128c T make_foo()

    所以我可以推断出包装这些的 SWIG 模块可能类似于:

    %module reversed
    
    class foo; // Nothing more known
    
    foo *make_foo();
    
    void frobinate_two_foos(foo*,foo*); // Return type guessed
    
    // ignored eat_foo, I don't know what that does at all!
    

    您仍然需要构建足够多的标头以允许生成的包装器编译。

    【讨论】:

    • 嗯.. 我想这对我来说很难,因为 dll 中有很多类型、依赖项和类型。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-12
    • 2016-12-05
    • 2011-02-12
    • 1970-01-01
    • 1970-01-01
    • 2014-09-07
    • 2019-05-24
    相关资源
    最近更新 更多