2

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.

1
  • Give us some more details about the source you want to compile: C/C++? do you have a Makefile? Do you need other libraries to link to? ... Commented Jan 30, 2013 at 9:13

2 Answers 2

4

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

1
  • Yes! I know how to build .so file for Linux. But don't know how to build a .dll for Windows.
    – Taras
    Commented Jan 30, 2013 at 9:00
2

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.