Taras
Taras

Reputation: 2576

How to build JNI .dll?

I have a java project in Eclipse that contains some JNI code. JNI code is cross platform - for Windows and Linux. How can I build a dll?

Thanks.

Upvotes: 2

Views: 5198

Answers (2)

TheWhiteRabbit
TheWhiteRabbit

Reputation: 15768

You have to build a .DLL for Windows and .so for Linux. You would compile C code in Linux using this syntax:

gcc -shared yourcode.c -I/usr/lib/gcc/x86_64-redhat-linux/3.4.3/include/ -o yourLib.so

import in java using

static {
        System.out.println(System.getProperty("java.library.path"));
        System.loadLibrary("yourlib");
    }

For Windows How to compile C to DLL

Upvotes: 4

Ortwin Angermeier
Ortwin Angermeier

Reputation: 6203

I assume you have some C/C++ code. To create a dll (windows) you have to compile your code (you could use Visual C++ Express for example, or mingw: gcc). In linux just use gcc to build the library.

Once you built the library for you platform add it to the library path with -Djava.library.path=<folder containing the library>.

hth

Upvotes: 2

Related Questions