Recently reviewed the C language and the Java language (10 useless, review), with JNI call C language DLL test, did not do before, on the internet to find a lot, summarized as follows:
Environment: Windows 10 (64-bit) + JDK (32-bit, version 1.7.0_79) + MinGW (32-bit), note that the JDK and MinGW are either 32-bit or 64-bit, not one 32-bit and the other 64-bit.
The Java and MINGW environment configurations are found on the web.
"No eclipse, manual editing with Notepad. Java and. C Programs"
1. The Hello.java code is as follows:
2, compile Hello.java program command: Javac Hello.java--Generate Hello.class file.
3. Generate Hello.h File command: Javah Hello--Generates HELLO.H header file, which is used in C language encoding, so Hello.h is stored in the same directory with the suffix. c file code.
4. The contents of ARR.C file are as follows:
5, c compilation Environment preparation: You need to copy the JDK corresponding jni_md.h and jni.h two files to the MinGW installation directory of the Include directory.
Jni_md.h under the%java_home%\ include\win32 directory; Jni.h in the%java_home%\ include directory.
6. Compile and build hello.dll Dynamic library file command:
GCC arr.c-shared-o hello.dll-wl,--kill-at
Command explanation:
-shared-o Hello.dll/* Specifies that the build target file Hello.dll is a dynamic library file */
-WL/* Tells the compiler to pass the following parameters to the linker */
-WL,--kill-at/* tells the linker to get rid of the @ sign of the function name suffix-the problem involves something more in-depth, for the time being, just follow the command, generate the. dll file, and implement the test. */
7, check the test directory E:\test the following files:
8, execute Java Hello, success!
Java JNI calls C-language DLL testing