【问题标题】:Errors Creating A Shared Library DLL for SWIG Packaged Simple Java Example (Windows)为 SWIG 打包的简单 Java 示例 (Windows) 创建共享库 DLL 时出错
【发布时间】:2012-03-30 04:24:36
【问题描述】:

我已经阅读了 SWIG 常见问题解答和动态模块文档,在决定如何为 Windows 构建 JNI 共享库 dll 时似乎有很多选择。 wiki 描述了使用非常旧版本的 Visual c++ 的过程。大家都在用什么?

我已经在 Windows 7 上安装了 MinGW 和以下命令,并在 SWIG 简单的 java 示例中运行了以下命令,见下文:

  • C:\swig\swigwin-2.0.4\Examples\java\simple>swig -java example.i
  • C:\swig\swigwin-2.0.4\Examples\java\simple>gcc -c example_wrap.c -I C:\Program F iles\Java\jdk1.6.0_30\include -I C:\Program Files\Java\jdk1.6.0_30\include\win32
  • C:\swig\swigwin-2.0.4\Examples\java\simple>gcc -shared example_wrap.o -o example.dll

最后一个命令错误:

example_wrap.o:example_wrap.c:(.text+0xa9): undefined reference to `gcd'
example_wrap.o:example_wrap.c:(.text+0xe2): undefined reference to `Foo'
example_wrap.o:example_wrap.c:(.text+0xe8): undefined reference to `Foo'
example_wrap.o:example_wrap.c:(.text+0x107): undefined reference to `Foo'
example_wrap.o:example_wrap.c:(.text+0x10d): undefined reference to `Foo'
collect2: ld returned 1 exit status

【问题讨论】:

    标签: gcc mingw swig


    【解决方案1】:

    看起来你要么没有编译,要么没有链接example.c,只有example_wrap.c。您需要执行以下操作:

    痛饮-java example.i gcc -c example_wrap.c -I somepath -I someotherpath gcc -c example.c -I somepath -I someotherpath gcc -shared example_wrap.o example.o -o example.dll

    【讨论】:

    • 修复了错误并生成了 dll,但看起来 dll 不包含正确的函数,因为我在线程“main”java.lang.UnsatisfiedLinkError: exampleJNI.gcd( II)I 运行 SWIG java 简单示例时。一切都在 Linux 上运行,所以可能有一些额外的编译参数或 Windwos 问题。有什么想法吗?
    • @c12 - 我不是 Windows DLL 构建问题的专家,但我认为您需要将其标记为 DLLEXPORT 和/或明确使用 stdcall - mingw.org/wiki/sampleDLL
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多