标签:
hadoop@Node4:/usr/local/eclipse/workspace/MongoLoc/bin$ javah -jni tong.mongo.loction.LinkedC
http://dikar.iteye.com/blog/382701
http://blog.sina.com.cn/s/blog_3f2c72ea01011kvx.html
http://www.cnblogs.com/javawebsoa/archive/2013/07/30/3225942.html
http://www.360doc.com/content/09/0402/09/107226_2994393.shtml
xuexiziliao http://blog.csdn.net/fengqiaoyebo2008/article/details/6210499
1.错误:
运行程序,在eclipse控制台出现
Java HotSpot(TM) Server VM warning: You have loaded library /usr/local/eclipse/workspace/MongoLoc/libSpeedEstimate.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: /usr/local/eclipse/workspace/MongoLoc/libSpeedEstimate.so: /usr/local/eclipse/workspace/MongoLoc/libSpeedEstimate.so: 错误 ELF 类: ELFCLASS64 (Possible cause: architecture word width mismatch) at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1965) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1890) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1880) at java.lang.Runtime.loadLibrary0(Runtime.java:849) at java.lang.System.loadLibrary(System.java:1088) at tong.mongo.loction.LinkedC.<clinit>(LinkedC.java:10) at tong.mongo.loction.MdbFind.main(MdbFind.java:173)
原因:
原因是编译使用的jvm是64位的,我们的系统jVM是32位的版本。c程序在64位系统下编译,不能在32位下用。
解决:
c程序重新在32位系统编译
2. 错误:
在命令窗口输入 gcc -shared -I /usr/local/bin/jdk1.7.0_71/include/ -I /usr/local/bin/jdk1.7.0_71/include/linux/ main.cpp -o libSpeedEstimate.so
进行编译
gcc: error trying to exec ‘cc1plus‘: execvp: 没有那个文件或目录
原因:
gcc 跟 g++ 版本不一致,或者没有安装g++
解决:
$sudo apt-get install g++
3. 错误:运行程序出现 libSpeedEstimate.so: undefined symbol: _ZNSt8ios_base4InitC1Ev
Exception in thread "main" java.lang.UnsatisfiedLinkError: /usr/local/eclipse/workspace/MongoLoc/libSpeedEstimate.so: /usr/local/eclipse/workspace/MongoLoc/libSpeedEstimate.so: undefined symbol: _ZNSt8ios_base4InitC1Ev at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1965) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1890) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1880) at java.lang.Runtime.loadLibrary0(Runtime.java:849) at java.lang.System.loadLibrary(System.java:1088) at tong.mongo.loction.LinkedC.<clinit>(LinkedC.java:10) at tong.mongo.loction.MdbFind.main(MdbFind.java:173)
原因:
译有问题,用g++ 编译可以,可能是有个cpp文件,gcc虽然能编译,但是生成的so文件格式有些问题,jni找不到接口,用g++就可以
原来的命令:
gcc -shared -I /usr/local/bin/jdk1.7.0_71/include/ -I /usr/local/bin/jdk1.7.0_71/include/linux/ main.cpp -o libSpeedEstimate.so
修改:
g++ -shared -I /usr/local/bin/jdk1.7.0_71/include/ -I /usr/local/bin/jdk1.7.0_71/include/linux/ main.cpp -o libSpeedEstimate.so
然后重新运行程序
见连接:http://bbs.csdn.net/topics/290013271
标签:
原文地址:http://www.cnblogs.com/gnivor/p/4430165.html