Java JNI編譯小記

來源:互聯網
上載者:User

  一直都做Android開發,而且編譯JNI代碼都是用Google提供的NDK,今天做個J2SE平台的JNI,發現離開Android平台還多少不習慣了,編譯so庫都弄了半天,記下編譯命令,以備後用。編譯前提安裝JDK和gcc/g++環境,我用的是gcc。步驟如下:

1.編譯Java原始碼
javac FifoTest.java

2. 產生*.H標頭檔
javah FifoTest.java

3.實現*.C檔案,如FifoTest.c
# coding...

4. 編譯*.c檔案產生 *.o檔案,這裡注意JDK路徑
gcc -c FifoTest.c -I./ -I/usr/lib/jvm/java-1.6.0-openjdk/include -I/usr/lib/jvm/java-1.6.0-openjdk/include/linux -o fifojni.o
(PS: -I optional with the jdk include file, you can find the include using this "locate include | grep java" to get the location of your jdk include)

#64位需要-fPIC選項
gcc -fPIC -c FifoTest.c -I./ -I/usr/lib/jvm/java-6-sun-1.6.0.26/include -I/usr/lib/jvm/java-6-sun-1.6.0.26/include/linux -o fifojni.o

5. 編譯*.o 檔案產生 *.so file
gcc -rdynamic -shared fifojni.o -o libfifo-jni.so

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.