我正在尝试使用JNI
为Rpi2
编译基本的C代码。我试图用rpi
直接在GCC
中进行操作。我尝试了许多不同的开关,但是没有任何效果,但是我仍然得到:
Java HotSpot(TM) Client VM warning: You have loaded library /tmp/libTestLibraryWrapper7702387558318276188.so which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
Exception in thread "main" java.lang.UnsatisfiedLinkError:
/tmp/libTestLibraryWrapper7702387558318276188.so:
/tmp/libTestLibraryWrapper7702387558318276188.so:
wrong ELF class: ELFCLASS64 (Possible cause: architecture word width mismatch)
我在用:
gcc -shared -march=armv7-a -mfpu=neon-vfpv4 -mfloat-abi=hard -c -g -I/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/include/ -I/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/include/linux -fPIC -MMD -MP -MF "build/Debug/GNU-Linux/testJava.o.d" -o build/Debug/GNU-Linux/testJava.o testJava.c
我现在有点卡住,所以任何提示都将不胜感激。
最佳答案
您可以尝试从此处使用示例:
http://jnicookbook.owsiak.org/recipe-No-001/
我能够在以下位置运行代码而没有任何问题:
cat /proc/cpuinfo
processor : 0
model name : ARMv6-compatible processor rev 7 (v6l)
BogoMIPS : 2.00
Features : half thumb fastmult vfp edsp java tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xb76
CPU revision : 7
Hardware : BCM2708
Revision : 0010
Serial : 00000000ee4a3dc2
只需执行以下操作:
git clone https://github.com/mkowsiak/jnicookbook.git
cd jnicookbook/recipeNo001/
export JAVA_HOME=$WHEREVER_YOUR_JAVA_IS
make test
应该给你结果:
make test
/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/bin/java -Djava.library.path=:./lib -cp target recipeNo001.HelloWorld
library: :./lib
Hello world!