<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>archive</title><link>https://archive-w.netlify.app/doc/advance/native/</link><description>Recent content on archive</description><generator>Hugo</generator><language>zh-CN</language><atom:link href="https://archive-w.netlify.app/doc/advance/native/index.xml" rel="self" type="application/rss+xml"/><item><title/><link>https://archive-w.netlify.app/doc/advance/native/javacpp/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://archive-w.netlify.app/doc/advance/native/javacpp/</guid><description>&lt;h2 id="example">
 example
 &lt;a class="anchor" href="#example">#&lt;/a>
&lt;/h2>
&lt;h6 id="accessing-native-apis" class="anchor_hr" style="font-size: 0rem; margin: 0; padding: 0; border-width: 0px;">&lt;/h6>&lt;div class="docsify-tabs docsify-tabs--classic">&lt;button anchorId="accessing-native-apis" class="docsify-tabs__tab" data-tab="Accessing Native APIS">Accessing Native APIS&lt;/button>&lt;div class="docsify-tabs__content" data-tab-content="accessing-native-apis">
&lt;h5 id="1-编写nativelibraryh">
 1. 编写NativeLibrary.h
 &lt;a class="anchor" href="#1-%e7%bc%96%e5%86%99nativelibraryh">#&lt;/a>
&lt;/h5>
&lt;div class="outer yosemite">&lt;div class="dot red">&lt;/div>&lt;div class="dot amber">&lt;/div>&lt;div class="dot green">&lt;/div>&lt;/div>
&lt;div class="code-toolbar">&lt;pre data-lang="cpp" data-line="" class="language-cpp line-numbers" style="max-height: none">&lt;code class="language-cpp">#include &amp;lt;string&amp;gt;

namespace NativeLibrary {
 class NativeClass {
 public:
 const std::string&amp;amp; get_property() { return property; }
 void set_property(const std::string&amp;amp; property) { this-&amp;gt;property = property; }
 std::string property;
 };
}
&lt;/code>&lt;/pre>&lt;/div>
&lt;h5 id="2-编写nativelibraryjava">
 2. 编写NativeLibrary.java
 &lt;a class="anchor" href="#2-%e7%bc%96%e5%86%99nativelibraryjava">#&lt;/a>
&lt;/h5>
&lt;div class="outer yosemite">&lt;div class="dot red">&lt;/div>&lt;div class="dot amber">&lt;/div>&lt;div class="dot green">&lt;/div>&lt;/div>
&lt;div class="code-toolbar">&lt;pre data-lang="java" data-line="" class="language-java line-numbers" style="max-height: none">&lt;code class="language-java">import org.bytedeco.javacpp.*;
import org.bytedeco.javacpp.annotation.*;

@Platform(include=&amp;quot;NativeLibrary.h&amp;quot;)
@Namespace(&amp;quot;NativeLibrary&amp;quot;)
public class NativeLibrary {
 public static class NativeClass extends Pointer {
 static { Loader.load(); }
 public NativeClass() { allocate(); }
 private native void allocate();

 // to call the getter and setter functions 
 public native @StdString String get_property(); public native void set_property(String property);

 // to access the member variable directly
 public native @StdString String property(); public native void property(String property);
 }

 public static void main(String[] args) {
 // Pointer objects allocated in Java get deallocated once they become unreachable,
 // but C++ destructors can still be called in a timely fashion with Pointer.deallocate()
 NativeClass l = new NativeClass();
 l.set_property(&amp;quot;Hello World!&amp;quot;);
 System.out.println(l.property());
 }
}
&lt;/code>&lt;/pre>&lt;/div>
&lt;h5 id="3-执行">
 3. 执行
 &lt;a class="anchor" href="#3-%e6%89%a7%e8%a1%8c">#&lt;/a>
&lt;/h5>
&lt;div class="outer yosemite">&lt;div class="dot red">&lt;/div>&lt;div class="dot amber">&lt;/div>&lt;div class="dot green">&lt;/div>&lt;/div>
&lt;div class="code-toolbar">&lt;pre data-lang="shell" data-line="" class="language-shell line-numbers" style="max-height: none">&lt;code class="language-shell">$ java -jar javacpp-1.5.9.jar NativeLibrary.java -exec
&lt;/code>&lt;/pre>&lt;/div>
&lt;h5 id="4-记录">
 4. 记录
 &lt;a class="anchor" href="#4-%e8%ae%b0%e5%bd%95">#&lt;/a>
&lt;/h5>
&lt;p>&lt;img src="https://archive-w.netlify.app/.images/doc/advance/native/javacpp-nl-01.png" alt="">&lt;/p></description></item><item><title/><link>https://archive-w.netlify.app/doc/advance/native/jna/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://archive-w.netlify.app/doc/advance/native/jna/</guid><description>&lt;h2 id="example">
 example
 &lt;a class="anchor" href="#example">#&lt;/a>
&lt;/h2>
&lt;h6 id="c-library" class="anchor_hr" style="font-size: 0rem; margin: 0; padding: 0; border-width: 0px;">&lt;/h6>&lt;h6 id="c-dynamic-library" class="anchor_hr" style="font-size: 0rem; margin: 0; padding: 0; border-width: 0px;">&lt;/h6>&lt;h6 id="c-dynamic-library-1" class="anchor_hr" style="font-size: 0rem; margin: 0; padding: 0; border-width: 0px;">&lt;/h6>&lt;h6 id="hikvision" class="anchor_hr" style="font-size: 0rem; margin: 0; padding: 0; border-width: 0px;">&lt;/h6>&lt;div class="docsify-tabs docsify-tabs--classic">&lt;button anchorId="c-library" class="docsify-tabs__tab" data-tab="C library">C library&lt;/button>&lt;div class="docsify-tabs__content" data-tab-content="c-library">
&lt;h5 id="1-导入需要的依赖包">
 1. 导入需要的依赖包
 &lt;a class="anchor" href="#1-%e5%af%bc%e5%85%a5%e9%9c%80%e8%a6%81%e7%9a%84%e4%be%9d%e8%b5%96%e5%8c%85">#&lt;/a>
&lt;/h5>
&lt;div class="outer yosemite">&lt;div class="dot red">&lt;/div>&lt;div class="dot amber">&lt;/div>&lt;div class="dot green">&lt;/div>&lt;/div>
&lt;div class="code-toolbar">&lt;pre data-lang="xml" data-line="" class="language-xml line-numbers" style="max-height: none">&lt;code class="language-xml">&amp;lt;!-- https://mvnrepository.com/artifact/net.java.dev.jna/jna --&amp;gt;
&amp;lt;dependency&amp;gt;
 &amp;lt;groupId&amp;gt;net.java.dev.jna&amp;lt;/groupId&amp;gt;
 &amp;lt;artifactId&amp;gt;jna&amp;lt;/artifactId&amp;gt;
 &amp;lt;version&amp;gt;5.13.0&amp;lt;/version&amp;gt;
&amp;lt;/dependency&amp;gt;
&lt;/code>&lt;/pre>&lt;/div>
&lt;h5 id="2-编写代码">
 2. 编写代码
 &lt;a class="anchor" href="#2-%e7%bc%96%e5%86%99%e4%bb%a3%e7%a0%81">#&lt;/a>
&lt;/h5>
&lt;p class="warn">The following program loads the local C standard library implementation and uses it to call the printf function. &lt;/br>
Note: The following code is portable and works the same on Windows and POSIX (Linux / Unix / macOS) platforms.&lt;/p></description></item><item><title/><link>https://archive-w.netlify.app/doc/advance/native/jni/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://archive-w.netlify.app/doc/advance/native/jni/</guid><description>&lt;h2 id="example">
 example
 &lt;a class="anchor" href="#example">#&lt;/a>
&lt;/h2>
&lt;h6 id="c" class="anchor_hr" style="font-size: 0rem; margin: 0; padding: 0; border-width: 0px;">&lt;/h6>&lt;h6 id="c-1" class="anchor_hr" style="font-size: 0rem; margin: 0; padding: 0; border-width: 0px;">&lt;/h6>&lt;h6 id="cc-mixture" class="anchor_hr" style="font-size: 0rem; margin: 0; padding: 0; border-width: 0px;">&lt;/h6>&lt;div class="docsify-tabs docsify-tabs--classic">&lt;button anchorId="c" class="docsify-tabs__tab" data-tab="C">C&lt;/button>&lt;div class="docsify-tabs__content" data-tab-content="c">
&lt;h5 id="1-写一段包含c方法实现的java代码">
 1. 写一段包含C方法实现的java代码
 &lt;a class="anchor" href="#1-%e5%86%99%e4%b8%80%e6%ae%b5%e5%8c%85%e5%90%abc%e6%96%b9%e6%b3%95%e5%ae%9e%e7%8e%b0%e7%9a%84java%e4%bb%a3%e7%a0%81">#&lt;/a>
&lt;/h5>
&lt;div class="outer yosemite">&lt;div class="dot red">&lt;/div>&lt;div class="dot amber">&lt;/div>&lt;div class="dot green">&lt;/div>&lt;/div>
&lt;div class="code-toolbar">&lt;pre data-lang="java" data-line="" class="language-java line-numbers" style="max-height: none">&lt;code class="language-java">// Save as HelloJNI.java
public class HelloJNI{
 static {
 // Load native library hello.dll (Windows) or libhello.so (Unixes) at runtime
 // This library contains a native method called sayHello()
 System.loadLibrary(&amp;quot;hello&amp;quot;);
 }
 // Declare an instance native method sayHello() which receives no parameter and returns void
 private native void sayHello();
 public static void main(String[] args){
 // Create an instance and invoke the native method
 new HelloJNI().sayHello();
 }
}
&lt;/code>&lt;/pre>&lt;/div>
&lt;p class="warn">The static initializer invokes System.loadLibrary() to load the native library &amp;ldquo;hello&amp;rdquo; (which contains a native method called sayHello()) during the class loading. It will be mapped to &amp;ldquo;hello.dll&amp;rdquo; in Windows; or &amp;ldquo;libhello.so&amp;rdquo; in Unixes/Mac OS X. This library shall be included in Java&amp;rsquo;s library path (kept in Java system variable java.library.path). You could include the library into Java&amp;rsquo;s library path via VM argument -Djava.library.path=/path/to/lib. The program will throw a UnsatisfiedLinkError if the library cannot be found in runtime.&lt;/p></description></item></channel></rss>