Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build a JNI DLL using MINGW

I am trying to create a DLL that will call Qt (currently I can't use Jambi for the functionality I need). I have a simple Java method:

public final native int createChild(int handle);

I created C project in Visual Studio Express 2010 and was able to build the DLL.

Then I created a project in Qt creator and moved my sources there. I tried to configure the build to a best of my knowledge but all I get is:

java.lang.UnsatisfiedLinkError: tools.proofofconcept.control.EmbedderComposite.createChild(I)I

My guess is that symbol is not properly exported from DLL. I added -D_JNI_IMPLEMENTATION_ linker arg:

g++ -D_JNI_IMPLEMENTATION_  -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -shared -mthreads -Wl -Wl,--out-implib,debug\libqt_integration.a -o debug\qt_integration.dll debug/dllmain.o debug/nativecode.o debug/qmfcapp.o debug/qwinwidget.o debug/moc_qwinwidget.o  -L"c:\Qt\2010.05-rc1\qt\lib" -lQtGuid4 -lQtCored4 
like image 935
Eugene Avatar asked Sep 10 '10 23:09

Eugene


People also ask

How do I create a DLL file in Mingw?

Open a command prompt, change to the directory where you extracted the files, and type "mingw32-make". The DLL and executable should be compiled, linked, and output as "AddLib. dll" and "AddTest.exe" in the "bin" directory. The import library will be created as "libaddlib.

What is JNA vs JNI?

Java Native Access (JNA) is a community-developed library that provides Java programs easy access to native shared libraries without using the Java Native Interface (JNI). JNA's design aims to provide native access in a natural way with a minimum of effort. Unlike JNI, no boilerplate or generated glue code is required.

What is JNI h file?

jni. h is a C/C++ header file included with the JDK that maps Java types to their native counterparts. javah automatically includes this file in the application header files.


1 Answers

I should've added following argument:

-Wl,--kill-at

It will change exported symbols format.

like image 61
Eugene Avatar answered Sep 20 '22 16:09

Eugene