Java JNI calls C-language DLL testing

Source: Internet
Author: User

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

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.