How to build JNI .dll?

蓝咒 提交于 2019-12-24 01:51:08

问题


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:


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




回答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



来源:https://stackoverflow.com/questions/14600025/how-to-build-jni-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!