MinGW的编译器选项Wl,-kill-at不起作用 [英] MinGW's compiler option Wl,--kill-at does not work

查看:562
本文介绍了MinGW的编译器选项Wl,-kill-at不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在努力使用Eclipse CDT和MinGW编译供JNI使用的Dll.

I am currently struggling to compile a Dll for JNI use, using Eclipse CDT and MinGW.

在学习完本教程之后,我创建了一个声明本机方法的Java类,然后使用javah获取相关的头文件,并在C ++类中实现了它.

Following a tutorial, i created a Java class that declares native methods, then used javah to get the relevant header file and I implemented it in a C++ class.

C ++代码非常简单并且可以编译,但是当我将库加载到Java类中时,出现此错误:

The C++ code is very simple and compilation works, but when I load the library into the Java class, i get this error :

Exception in thread "main" java.lang.UnsatisfiedLinkError: Main.integerMethod(I)I
    at Main.integerMethod(Native Method)
    at Main.main(Main.java:12)

我研究"了该dll,发现应该调用的所有方法都有一个后缀,例如"@ 14".问题是,我已经在使用-Wl,-kill-at编译器选项,该选项应该删除这些非常令人尴尬的标记...那为什么它不起作用?

I "explored" the dll and found out that the methods that should be called all have a suffix like "@14". The problem is, I am already using the -Wl,--kill-at compiler option which should remove these very embarassing tags... So why is it not working ?

编译日志如下:

**** Rebuild of configuration DLL for project JniCTest ****

**** Internal Builder is used for build               ****
g++ -IC:\Program Files\Java\jdk1.6.0_13\include -IC:\Program Files\Java\jdk1.6.0_13\include\win32 -O3 -Wall -c -fmessage-length=0 -mno-cygwin -D__int64=long long -Wall -D_JNI_IMPLEMENTATION_ -Wl,--kill-at -oMain.o ..\Main.cpp
g++ -o libJniCTest.dll -Wall -D_JNI_IMPLEMENTATION_ -Wl,--kill-at -shared -olibJniCTest.dll Main.o
Build complete for project JniCTest
Time consumed: 375  ms.  

编译器选项有问题吗?感谢您的帮助.

Is there something wrong about the compiler options ? Thanks for any help.

推荐答案

找到解决方案. --kill-at选项未放入正确的命令中.实际上,MinGW首先将文件编译成.o目标文件,然后(第二行)从该.o文件进行链接.因此,该选项必须放在第二行.

Solution found. The --kill-at option was not put in the right command. Indeed MinGW first compiles the files into an .o object file, then (second line) it does the linking from this .o file. The option must therefore be placed into the second line.

针对源文件Main.cpp和输出DLL libJniCTest.dll的更正命令:

Corrected commands for a source file Main.cpp and an output DLL libJniCTest.dll :

g++ -I"C:\Program Files\Java\jdk1.6.0_13\include" -I"C:\Program Files\Java\jdk1.6.0_13\include\win32" -O0 -Wall -c -oMain.o ..\Main.cpp
g++ -Wl,--kill-at -shared -olibJniCTest.dll Main.o

这篇关于MinGW的编译器选项Wl,-kill-at不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆