我使用javacpp从Java访问CPP。
我曾尝试在文档中提供的示例
CPP代码:
#include <string>
namespace LegacyLibrary {
class LegacyClass {
public:
const std::string& get_property() { return property; }
void set_property(const std::string& property) { this->property = property; }
std::string property;
};
}
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());
}
}
在Eclipse我的文件夹结构
我收到以下错误,如果我在Eclipse中运行LegacyLibrary.java文件
异常线程“main” java.lang.UnsatisfiedLinkError中:在java.lang.ClassLoader.loadLibrary(来源不明)在java.lang.Runtime.loadLibrary0(来源不明)在java.lang.System中的中的java.library.path没有jniLegacyLibrary .loadLibrary(未知来源)在org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:550)在org.bytedeco.javacpp.Loader.load(Loader.java:415)在org.bytedeco.javacpp.Loader.load (Loader.java:358)在LegacyLibrary $ LegacyClass。(LegacyLibrary.java:8)在LegacyLibrary.main(LegacyLibrary.java:22)
什么是错我的代码?