JNI/C++编译问题
JNI/C++ compiling problems
我是C++新手,并尝试编译一个.so文件以通过Java中的JNI运行它。
C++文件夹的目录结构为:
/
/lib/ - this contains a .a file = library.a below
/folder1 - this contains the .cpp .h and .o files
场景 1:
我正在运行以下内容:
g++ -std=c++11 -I$JAVA_HOME/include -Ifolder1/ -I$JAVA_HOME/include/linux -o outputFileName.so inputFileName.cpp -Llib -llibrary.a -fPIC -shared
我收到以下错误:
relocation R_X86_64_32 against '.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
所有文件和 .so 对象都有 -fPIC 标志。问题出在哪里?
场景 2:
我正在运行以下内容:
g++ -std=c++11 -I$JAVA_HOME/include -Ifolder1/ -I$JAVA_HOME/include/linux -o outputFileName.so inputFileName.cpp -shared
所以没有 -L 和 -l 标志。
我得到 .so 文件并将其放在带有相关命名的/usr/lib 中,即"lib"前缀。当我运行Java程序时,我得到:
symbol lookup error: /usr/lib/outputFileName.so: undefined symbol: _ZN3...
我使用 c++filt 来反编译符号,并得到对类似这样的类的引用:
namespace::Class::Constructor
我检查了类的.cpp文件,构造函数存在。
请帮忙?
请在此处查看示例代码,您可以在其中了解 JNI 如何使用其他共享库。
https://github.com/mkowsiak/jnicookbook/blob/master/recipes/recipeNo023/Makefile
看起来您引用了 .so 文件使用的某种库。
确保将它们放在您的LD_LIBRARY_PATH - 而不仅仅是您的 JNI 库。
相关文章:
- 编译包含字符串的代码时遇到问题
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 编译要在英特尔Hyperscan中使用的.cc文件时出现问题
- 如何在 Mac 上正确编译C++,当它在 Linux 上编译没有问题时?
- Rextester 语言编译C++问题
- 这是使用回溯的 nqueen 问题,但我使用了动态 2d 数组,我的程序编译良好,但不返回任何输出
- 编译 llvm 插件时出现问题:llvm/Config/llvm-config.h:没有这样的文件或目录
- C++ 多级虚拟继承编译问题
- 编译问题:在函数"_start"中:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- 在Linux上使用Clang / OLLVM交叉编译helloworld Windows可执行文件时的问题
- 使用 CImg 库的 std::min 和 std::max 的编译问题
- Qt Visual Studio 2015 加载项编译问题
- 构造函数和 G++ 编译配方的问题
- 解析问题 - 预期的非限定 ID - #include <array> 编译错误
- libssh 问题编译问题未定义的错误
- Eclipse 问题 - 编译期间不考虑 .c 和 .cpp 文件中定义的预处理
- Visual Studio 2017问题编译了C 代码,而该代码则在Linux中编译
- 这个C++代码有什么问题?编译错误:调用“测试::测试(测试)”没有匹配函数
- 试图编译基本Boost PropertyTree示例时出现问题-编译错误.该怎么做
- 如何解决***缺少分隔符的问题.编译QT(或支持库)时