JNI使用過程中的錯誤

來源:互聯網
上載者:User

標籤:

 [email protected]:/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

JNI使用過程中的錯誤

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.