gpt4 book ai didi

java - 遵循Netbeans JNI基础教程时出错

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

我正在关注这个Netbeans tutorial for JNI但是当我构建 JNIDemo.c 库时,我在 Netbeans 输出中收到此错误:

    "/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .clean-conf
make[1]: Entering directory `/home/username/Documents/JavaProjects/JNIDemoCd1'
rm -f -r build/Debug
rm -f dist/libJNIDemoCdl.so
make[1]: Leaving directory `/home/username/Documents/JavaProjects/JNIDemoCd1'

CLEAN SUCCESSFUL (total time: 54ms)
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/username/Documents/JavaProjects/JNIDemoCd1'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/libJNIDemoCdl.so
make[2]: Entering directory `/home/username/Documents/JavaProjects/JNIDemoCd1'
mkdir -p build/Debug/GNU-Linux-x86
rm -f "build/Debug/GNU-Linux-x86/JNIDemo.o.d"
gcc -shared -m32 -c -g -I/opt/jdk1.7.0_67/include -I/opt/jdk1.7.0_67/include/linux -include /opt/jdk1.7.0_67/include -include /opt/jdk1.7.0_67/include/linux -fPIC -MMD -MP -MF "build/Debug/GNU-Linux-x86/JNIDemo.o.d" -o build/Debug/GNU-Linux-x86/JNIDemo.o JNIDemo.c
In file included from <command-line>:0:0:
/usr/include/stdc-predef.h:59:1: fatal error: /opt/jdk1.7.0_67/include: No such file or directory
#endif
^
compilation terminated.
make[2]: *** [build/Debug/GNU-Linux-x86/JNIDemo.o] Error 1
make[2]: Leaving directory `/home/username/Documents/JavaProjects/JNIDemoCd1'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/username/Documents/JavaProjects/JNIDemoCd1'
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 119ms)

谢谢大家!

最佳答案

解决了!!
这是架构的问题。

我使用选项 -m32 编译了该库正如教程所说,在 C 项目属性中,但我的虚拟机是 64 位机器,所以我必须使用 -m64 .

这意味着什么?当有人使用 JNI 时,有必要将我们的 VM 的架构与库的架构相匹配。

如何查看我们库的架构?在 Linux 终端中,输入:
objdump -f my_lib.so | grep ^architecture .

这样你就可以得到类似的东西(x32):architecture: i386, flags 0x00000150:
或者像这样(x64):architecture: i386:x86-64, flags 0x00000150:

所以,我输入 -m64而不是-m32在属性和“et voilà!”中,VM 64 位和库 64 位一起工作。感谢大家。

关于java - 遵循Netbeans JNI基础教程时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26964031/

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