我正在关注此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)
谢谢你们!
答案 0 :(得分:0)
解决!!
这是架构的一个问题。
我在C项目属性中使用选项-m32
编译了库,如教程所述,但我的虚拟机是64位机器,所以我必须使用-m64
。
这意味着什么?当有人与JNI合作时,有必要将我们VM的架构与库的架构相匹配。
如何检查我们图书馆的架构?
在linux终端中,键入:
objdump -f my_lib.so | grep ^architecture
。
有了这个,你可以得到类似的东西(x32):architecture: i386, flags 0x00000150:
或者像这样(x64):architecture: i386:x86-64, flags 0x00000150:
所以,我在属性和“etvoilà!”,VM 64位和库64位一起工作时放了-m64
而不是-m32
。谢谢大家。