Build a dll in C++ for java which is calling another dll (JNI on Eclipse)

D. Vercammen

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 !

Smeeheey

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Monitoring memory usage for a C DLL called with Java via JNI?

From Java

Java app calls C++ DLL via JNI; how best to allocate memory?

From Java

Calling a DLL from an Applet via JNI

From Java

Importing DLL into Eclipse Java project

From Java

Build a JNI DLL using MINGW

From Java

Calling C++ dll from Java

From

Calling Golang from Java using JNI on Windows leads to "A dynamic link library (DLL) initialization routine failed"

From Dev

Load a C++ DLL into matlab which calls functions in another DLL

From Dev

Calling a function from a DLL which is developed in C++ from C

From Dev

Calling C++ DLL in NodeJS asynchronous

From Dev

C# calling dll file of Delphi

From Dev

C++ calling DLL functions

From Dev

Call fortran dll from java using JNI

From Dev

Calling dll implemented JNI from C++

From Dev

JNI Java using DLL function which takes an object as param

From Dev

Calling C++ dll from python

From Dev

Calling function in C dll from C# which returns somekind of pointer to function pointer

From Dev

JNI to call .NET dll

From Dev

Dll calling another dll with JNA

From Dev

Calling a method in a C dll fails

From Dev

Using managed dll (which uses unmanaged dll) in c# project

From Dev

Calling methods inside .dll File in c#

From Dev

Calling convention for an unmanaged DLL in C#

From Dev

Calling a C dll through chrome browser extension

From Dev

Calling DLL from another namespace

From Dev

Error while calling function through C DLL

From Dev

Calling JNI C function in another source file

From Dev

C# calling fortran dll stack overflow

From Dev

Calling C# DLL in Python TypeLoadException error

Related Related

HotTag

Archive