我使用javacpp從Java訪問cpp。運行javacpp時java.lang.UnsatisfiedLinkError
我曾嘗試文檔中提供的例子
cpp的代碼:
CompletableFuture<Integer> futureInC(){
@StdFuture f = @cppDemo.futureInC();
CompletableFuture<Integer> future = new CompletableFuture<>();
f.then(int value -> future.complete(value));
return future;
}
Java代碼:
import org.bytedeco.javacpp.*;
import org.bytedeco.javacpp.annotation.*;
@Platform(include="LegacyLibrary.h")
@Namespace("LegacyLibrary")
public class LegacyLibrary {
public static class LegacyClass extends Pointer {
static { Loader.load(); }
public LegacyClass() { 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()
LegacyClass l = new LegacyClass();
l.set_property("Hello World!");
System.out.println(l.property());
}
}
我收到以下錯誤,如果我運行NativeLibrary.java文件Intellij Idea:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jniNativeLibrary in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:597)
at org.bytedeco.javacpp.Loader.load(Loader.java:438)
at org.bytedeco.javacpp.Loader.load(Loader.java:381)
at com.viettel.demo.NativeLibrary$NativeClass.<clinit>(NativeLibrary.java:13)
at com.viettel.demo.NativeLibrary.main(NativeLibrary.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
如何在Intellij Idea中運行示例javacpp,我確實嘗試了在Readme.md中沒有問題的guilde後面的命令行。 感謝您的支持!
你在說什麼文檔?請鏈接 –
https://github.com/bytedeco/javacpp 我正在使用javacpp進行JNI C++到Java –