Java JNI compilation note

Source: Internet
Author: User

I have been doing Android development all the time, and compiling JNI code is using the ndk provided by Google. Today I am a jni on the j2se platform, and I find that I am not used to leaving the Android platform, after compiling the so library for a long time, write down the compilation command for later use. Install the JDK and the GCC/g ++ environment before compiling. I use GCC. The procedure is as follows:

1. compile Java source code
Javac synchronized otest. Java

2. Generate the *. h header file
Javah implements otest. Java

3. Implement the *. c file, such as unzip otest. C.
# Coding...

4. Compile *. c file to generate *. o file. Pay attention to the JDK path here.
Gcc-C embedded otest. c-I. /-I/usr/lib/JVM/java-1.6.0-openjdk/include-I/usr/lib/JVM/java-1.6.0-openjdk/include/Linux-O unzip ojni. 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-bit-FPIC options
Gcc-FPIC-C Release otest. 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 Required ojni. O

5. Compile *. o file to generate *. So file
Gcc-rdynamic-shared writable ojni. O-o libfifo-jni.so

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.