Step 5: create a shared library file
Next, we will create a localCode.
In addition to creating executable machine code files, most C and C ++ compilers can also create shared library files.
The command used to create shared library files depends on the compiler you use.
The following commands are executed in windows.
Windows:
Use Visual Studio commandprompttool cl.exe
CL-I "C: \ Program Files \ Java \ jdk1.6.0 _ 10 \ include"-I "C: \ Program Files \ Java \ jdk1.6.0 _ 10 \ include \ Win32 "-LD test_jni_javacallc_test.c-Fe test_jni_javacallc_test.dll
You can also use vc6.0 to directly create a dynamic library.
During compilation, JNI-related header files and library files are required. Add two Java-related paths to the search path of vc6.0.
Tools> sptions> Directories
Linux: using the GCC Tool
Gcc-C-FPIC-I/usr/Java/jdk1.6.0 _ 22/include/-I/usr/Java/jdk1.6.0 _ 22/include/Linux/sample1.c
Gcc-shared-FPIC-O libsample1.so sample1.o
Step 6: run JavaProgram
The last step is to run the Java program and ensure that the code works correctly.
Because all Java code must be executed in the Java virtual machine, you need to use the Java Runtime Environment.
One way to complete this step is to use Java, which is a Java interpreter provided along with the SDK.
The command used is:
Java-CP. Test.Test_jni_javacallc_test
Or run it directly in the external ose.
Output:
Intmethod: 25
Booleanmethod: false
Stringmethod: Java
Intarraymethod: 33