gpt4 book ai didi

java - 在 Ubuntu 下使用 JNI 在 IntelliJ 中包含 native c++ .so 库

转载 作者:行者123 更新时间:2023-11-30 08:45:29 25 4
gpt4 key购买 nike

我正在构建一个共享库,它将在 Ubuntu 14.04 x64 下使用 JNI 从 Java IntelliJ 调用。在 Intellij 中使用 System.loadLibrary("libtestJniLib") 调用我的 .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 下启动。

最佳答案

当您使用 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.

关于java - 在 Ubuntu 下使用 JNI 在 IntelliJ 中包含 native c++ .so 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33281897/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com