JAVA Building using Native Library __ humanoid robot

Source: Internet
Author: User
Tags naming convention

Java uses native files, which are generally decomposed into the following steps:

To declare a local method run Javah using the native keyword in Java code, get the C language header file that contains the method declaration (the C function name in JNI programming is usually related to a Java method with a certain naming convention, which is described later. We use Javah to help us get the name of the method. Generate shared library files in C or C + + to implement the functionality we need, shared library files can be Windows-style. dll files, or UNIX-style. so files To ensure that the virtual machine loads the library the first time it uses the class, the static initialization block is used to load the

Operation Steps:

1.CMD Switch to Directory

CD D:\Works\Android\WorkspaceUnify\rsPolylabel\bin
D:

2. Compile header file
Javah-jni-classpath. -D./jni Rspolylabel.polylabel

Result: Generate h file rspolylabel_polylabel.h to Jni folder

3. Header File Code description
/* Do isn't EDIT this file-it is machine generated/*
#include <jni.h>/
* Header for Class rspolylabel_polyl Abel/

#ifndef _included_rspolylabel_polylabel
#define _included_rspolylabel_polylabel
#ifdef __ Cplusplus
extern "C" {
#endif/*
 Class:     Rspolylabel_polylabel
 * Method:    Hellowishchinjni
 * Signature: () V
 /
jniexport void Jnicall java_rspolylabel_polylabel_ Hellowishchinjni
  (jnienv *, jclass);

#ifdef __cplusplus
}
#endif
#endif


5. Use vs Generation Project

Use VS to build a DLL project, write the appropriate CPP file from the header file, and add a table of contents to the Include directory:

C:\Program Files\java\jdk1.8.0_152\include

And

C:\Program Files\java\jdk1.8.0_152\include


7. Load Dynamic Library

Online method of storing DLL files directory to add to the system directory path, and then the egg ...

In the Eclipse program, run System.out.println (System.getproperty ("Java.library.path"));

This row runs complete, output directory

D:\Works\Android\WorkspaceUnify\rsPolylabel\lib\x64;

D:\Works\Android\WorkspaceUnify\rsPolylabel\lib\hdf5

So put the DLL file into the lib\x64 directory and load it successfully.


6. Write code

Add header file contains and JNI included in CPP file

#include <jni.h>/
* Header for Class Rspolylabel_polylabel * *
#include "rspolylabel_polylabel.h"

After that, you can build a dynamic library in a normal way


7. Introduction of Dynamic Library

The test was successful.


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.