I'm actually working on a project which is using the JNI on Eclipse.
Actually, I build a dll in C++ part and I use it in the Java part.
But, now I need to call a dll in the C++ part (because I need to use a existing project) and use the function in the C++ part and then build the dll to use it in Java. So I need to create a dll which is calling another dll.
How can I do that ?
Thank you in advance !
To build a dll you would use the -shared
option with your compiler when creating the final binary. In order to use other existing dlls within this dll, the easiest option is to create the link statically (not be confused with linking to static libraries, you'll still be using the other dll itself dynamically at runtime). If you're doing this you can specify the dll in question using the -l
(and possibly the -L
) switch(es).
For example, assuming your dll will be my_dll.dll
made from the source file my_dll.cpp
and using an external dll called other_dll.dll
, you could have something like:
g++ -c my_dll.cpp
g++ -shared -o my_dll.dll my_dll.o -lother_dll -L/path/to/other/dll
In your code (my_dll.cpp
) you would include the header files provided by the supplier of other_dll.dll
in order to access its exported functions, and just call them normally from your code (just like functions included from headers and defined with other cpp
files of your own project). The same goes for the usage of any classes defined in other_dll.dll
: simply include the headers that declare them and use them (and their member functions) as normal.
This link describes how to code up an example library with MingGW.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments