This question regards a similar problem then JNI %1 is not a valid Win32 application .
I also want to compile a 64 bit static lib from C++ source to use within Java and I also get the error:
Exception in thread "Thread-2" java.lang.UnsatisfiedLinkError: C:\Users\boon\AppData\Local\Temp\keyboardhook-3382807930283923158.lib: %1 is no valid Win32 application
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at de.ksquared.system.keyboard.Native.load(Native.java:79)
at de.ksquared.system.keyboard.KeyboardHook.(KeyboardHook.java:84)
at de.ksquared.system.keyboard.PoolHook.run(KeyboardHook.java:51)
whereas I want to compile the KeyboardHook from Kristian Kraljic (http://kra.lc/blog/2011/07/java-global-system-hook/ ) with some added functionality in the library. First I tried to compile my KeyboardHook.cpp with Microsoft Visual Studio 2013 but there the compile flags Kristian suggested were all ignored and I also got the same exception mentioned above. Thus I changed the compiler to MinGW and the compiling is successful with the following command:
g++ -Wall -c -D_JNI_IMPLEMENTATION_ -Wl,-kill-at -O0 -g3 -fmessage-length=0 -static-libgcc -I”%JAVA_HOME%\include” -m64 -I”%JAVA_HOME%\include\win32″ -shared -o keylib.lib KeyboardHook.cpp
most the of flags I took over from Kristians suggestion. The problem seems to be that the generated .lib file seems still not be fully 64bit. The gcc -dumpmachine
tells me: x86_64-w64-mingw32
, thus both 32bit and 64bit as targets should be possible. With the flag -m64
it should compile with 64 bit however or? I am using the minGW build x64-4.8.1-win32-seh-rev5
, Windows 7 64bit and Java7.
I don't know at the moment where else I can find a mistake. Do I have to set the linker flags differently?