Compiling 64 bit DLL for JNI
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'...
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.
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
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?