为 JNI 编译 64 位 DLL
我想通过 JNI 在我的 Java 项目中包含一个 C 库。我编写了必要的 JNI 包装器代码,并使用 gcc 和 make 在 Linux 环境中对其进行了编译和测试。现在我需要编译它以生成 64 位 Windows DLL,但我无法编译它。
我下载了 Visual C++ Express 2010,并且一直在命令行上使用 cl.exe。在不知道任何更好的方法的情况下,我刚刚使用我想要编译的所有文件作为参数调用了 cl.exe。我收到各种错误:
Command line warning D9024: unrecognized source file type 'svm_jni.h'...
并且
svm_jni.c(63) : error C2275: 'jobject' : illegal use of this type as an expression...
我发现的第一个问题是 cl.exe 不接受 .h 文件(我猜它仅适用于 C++ 而不是 C?)。有解决方法吗?我可以将所有 .h 文件更改为 .c 文件并更改包含语句,但我不想这样做。
我尝试在 MinGW 上使用 make 和 gcc 进行编译,但它总是说无法编译为 64 位目标。
我尝试过使用 makefile 项目类型通过 VC++ 执行操作,但我无法弄清楚它是如何工作的。
有什么建议吗?
编辑:我从命令行参数中删除了 .h 文件,这解决了部分问题。我一直用来
-I "C:\Program Files\Java\jdk1.6.0_21\include" -I "C:\Program Files\Java\jdk1.6.0_21\include\win32"
获取jni.h和jni_md.h。 之后我仍然收到
svm_jni.c(63) : error C2275: 'jobject' : illegal use of this type as an expression
C:\Program Files\Java\jdk1.6.0_21\include\jni.h(83) : see declaration of 'jobject'
一堆语法和奇怪的错误。我假设所有错误都是常见问题的结果,但我不知道出了什么问题。
jni_md.h 有 64 位版本吗?我现在使用的是\include\win32
I want to include a C library in my Java project via JNI. I wrote the necessary JNI wrapper code and I have compiled and tested it in a Linux environment using gcc and make. Now I need to compile this to make a 64 bit Windows DLL, and I cannot get it to compile.
I downloaded Visual C++ Express 2010 and I have been using cl.exe on the command line. In the absence of knowing any better way to do it, I have just called cl.exe with all of the files I want to compile as arguments. I get a variety of errors:
Command line warning D9024: unrecognized source file type 'svm_jni.h'...
and
svm_jni.c(63) : error C2275: 'jobject' : illegal use of this type as an expression...
The first problem I have discovered is do to the fact that cl.exe does not accept .h files (I guess its only meant for C++ instead of C?). Is there a workaround for this? I could change all of the .h files to .c files and change the include statements, but I would prefer not to do this.
I have tried compiling using make and gcc on MinGW, but it always says that it cannot compile to a 64 bit target.
I have tried doing things through VC++ using the makefile project type, but I could not figure out how that works.
Any suggestions?
EDIT: I removed the .h files from the command line arguments and that solves part of the problem. I have been using
-I "C:\Program Files\Java\jdk1.6.0_21\include" -I "C:\Program Files\Java\jdk1.6.0_21\include\win32"
to get jni.h and jni_md.h. I still get
svm_jni.c(63) : error C2275: 'jobject' : illegal use of this type as an expression
C:\Program Files\Java\jdk1.6.0_21\include\jni.h(83) : see declaration of 'jobject'
and a bunch of syntax and weird errors after that. I am assuming all the errors are the result of a common problem, but I don't know whats going wrong.
Is there a 64 bit version of jni_md.h? The one I'm using now is in \include\win32
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您并不是真的想编译头文件,而是想在编译 c/c++ 文件时将它们包含在编译路径中。
对于jobject问题,您需要包含位于%JAVA_HOME%\include目录下的jni头文件。
对于 Visual C++ Express,您是否下载了 64 位构建工具?当您声明 gcc 和 MinGW 无法编译为 64 位目标时,您到底得到了什么消息?你有 minGW-w64 吗?
You don't really want to compile the header files, rather you want to include them in your compilation path when you compile the c/c++ files.
As for the jobject issue, you need to include the jni header files which are located under the %JAVA_HOME%\include directory.
For Visual C++ Express, did you download the 64 bit building tools? And when you state that gcc and MinGW cannot compile to a 64 bit target, what message are you getting exactly? Do you have minGW-w64?