Search code examples
javaeclipsedlljava-native-interfacecygwin

Build DLL for JNI using Eclipse


I want to build a JNI DLL using Eclipse and Cygwin. I know there are a lot of examples out there, but non of them work for me. I've spent 2 days on this and I still can't get Eclipse to build a frickin dll properly.

I can build this Windows dll in Visual studio with JNI code fine. But my main IDE is Eclipse and I want the code in one place, one project. When I compile this in Eclipse I'll get a dll out of it but the Java VM crashes at the loading of the library, with no error telling me whats wrong. So I'm thinking its the way I linked this...Here is how VS2008 does the compile and link I am showing the command line for VS:

compile and linking for dll using visual studio

/Od /I "C:\a_Mine\siglib\include" /I "C:\Program Files (x86)\Java\jdk1.6.0_25\include
\win32" /I "C:\Program Files (x86)\Java\jdk1.6.0_25\include" /I "..\..\include" /D 
"_CRT_SECURE_NO_WARNINGS" /D "SIGLIB_DLL_SOURCE=1" /D "_VC80_UPGRADE=0x0600" /D 
"_WINDLL" /D "_MBCS" /Gm /EHsc /RTC1 /MTd /Fp".\Debug/dynamic_library.pch" 
/Fo".\Debug/" /Fd".\Debug/" /W3 /nologo /c /ZI /TP /errorReport:prompt

Linker MS command line

/OUT:"Debug/siglib.dll" /INCREMENTAL /NOLOGO /LIBPATH:"C:\Program Files (x86)\Java\jdk1.6.0_25\lib" 
/DLL /MANIFEST /MANIFESTFILE:".\Debug\siglib.dll.intermediate.manifest" 
/MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:".\Debug/siglib.pdb" 
/DYNAMICBASE:NO /IMPLIB:".\Debug/siglib.lib" /MACHINE:X86 /ERRORREPORT:PROMPT 
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib 
ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

and here is my linker for the Eclipse Java - C/C+ project.

g++ -L"C:\Program Files (x86)\Java\jdk1.6.0_25\lib" -L"C:\Program Files\Microsoft
SDKs\Windows\v6.0A\Lib\x64" -shared -o "myjni.dll" $(OBJS) $(USER_OBJS)  -lkernel32 
-luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 
-luuid -lodbc32 -lodbccp32 -ljvm

So how do I get this to link or compile right using Eclipse Cygwin?


Solution

  • You should update your eclipse to the latest and get ADT ver20. This removes cygwin from the build and all the custom scripts you may need to compile a windows dll.