2015-10-22 35 views
2

我正在构建一个共享库,它将在Ubuntu 14.04 x64下使用JNI从Java IntelliJ调用。 当调用的IntelliJ使用System.loadLibrary("libtestJniLib")我的.so文件,我得到了以下错误:在Ubuntu下使用JNI在IntelliJ中包含native C++ .so库

Exception in thread "main" java.lang.UnsatisfiedLinkError: no 
libtestJniLib in java.library.path 

的配置的IntelliJ确定库的路径:

1) Run->Edit Configurations->VM options: -Djava.library.path=/home/username/Libs 
2) In "Project structure -> Libraries ->Native library locations" 

我加了相同的路径:/home/username/Libs

当使用下面提到的方法测试它时,我有一条正确的路径。

String javaLibPath = System.getProperty("java.library.path"); 

IntelliJ以root启动。

+0

什么的全名您的图书馆,包括扩展? –

+0

库名称是libtestJniLib.so – restfuldon

回答

1

当你加载使用System.LoadLibrary()共享库,应用如下:

Loads the system library specified by the libname argument. The manner in which a library name is mapped to the actual system library is system dependent.

我能找到该映射的最好描述是here

Each Java runtime environment provides a platform-dependent mechanism for mapping between the actual file name of a shared library and the name string that you pass as an argument to the System.loadLibrary method.

Solaris:

The shared library file name requires a "lib" prefix and a ".so" extension. Do not include the "lib" prefix or the ".so" extension for the argument that you pass to the System.loadLibrary method.

Microsoft Windows:

The shared library file name requires a ".dll" extension.
Do not include the ".dll" extension for the System.loadLibrary method argument.