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