1

I try to compile and link a *.c file (to use with the jni) on linux to target windows 64bit with mingw-w64. I do

x86_64-w64-mingw32-gcc -I"path/to/headers" -shared -o output.dll input.c

Everything compiles and I get a 64bit *.dll as file output.dll shows:

output.dll: PE32+ executable (DLL) (console) x86-64, for MS Windows

But on my 64bit windows java throws an Unsatisfied link error because some libraries, my dll depends on, are missing. So I downloaded Dependency Walker and opened the dll file. It shows me that the *.dll file is linked with the 32bit (x86) versions of the dlls I depend on instead the 64 bit dlls. Only my dll is 64bit (x64). I looked into C:\Windows and found out that also the 64bit dlls are present.

So I tried to fix this by adjusting the arguments in the mingw command. In the manual-entry for ld I found option -L to specify a path dependencies. So I tried the following:

x86_64-w64-mingw32-gcc -Wl,-L"/usr/x86_64-w64-mingw32/lib/" -I"path/to/headers" -shared -o output.dll input.c
x86_64-w64-mingw32-gcc -Wl,-L"/usr/x86_64-w64-mingw32/lib/",-static -I"path/to/headers" -shared -o output.dll input.c
x86_64-w64-mingw32-gcc -Wl,-static -I"path/to/headers" -shared -o output.dll input.c
x86_64-w64-mingw32-gcc -m64 -I"path/to/headers" -shared -o output.dll input.c

Note: /usr/x86_64-w64-mingw32/lib/ is the directory where mingw's 64bit *.a files are located.

The above commands didn't seem to have any effect on my output dll. It stays 64 bit but linked to 32bit dlls. I have no idea what to do to get this work.

Also when I compile this for 32 bit using i686-w64-mingw32-gcc everything works fine and I get a 32bit dll linked with the 32bit dlls in windows.

My windows is windows 7 home premium and I use java 11 by the way.

EDIT: I know this question but the answer doesn't work for me.

1 Answer 1

1

Ok, I have no idea why it didn't work. When I tried again 3 days later, the command

x86_64-w64-mingw32-gcc -Wl,-L"/usr/x86_64-w64-mingw32/lib/" -I"path/to/headers" -shared -o output.dll input.c 

works perfectly fine. So if you have the same issue, I'd recommend to reboot your computer and try the command above.

You must log in to answer this question.