Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.lang.UnsatisfiedLinkError:java.library.path中没有jniLegacyLibrary_Java_C++_Eclipse_Javacpp - Fatal编程技术网

java.lang.UnsatisfiedLinkError:java.library.path中没有jniLegacyLibrary

java.lang.UnsatisfiedLinkError:java.library.path中没有jniLegacyLibrary,java,c++,eclipse,javacpp,Java,C++,Eclipse,Javacpp,我正在使用从Java访问cpp 我已经尝试了文档中提供的示例 cpp代码: #include <string> namespace LegacyLibrary { class LegacyClass { public: const std::string& get_property() { return property; } void set_property(const std::string&am

我正在使用从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;
    };
}
eclipse中的我的文件夹结构

如果在Eclipse中运行LegacyLibrary.java文件,我会遇到以下错误

线程“main”java.lang.UnsatifiedLinkError中出现异常:java.library.path中没有jniLegacyLibrary 位于java.lang.ClassLoader.loadLibrary(未知源) 位于java.lang.Runtime.loadLibrary0(未知源) 位于java.lang.System.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)


我的代码有什么问题?

您已经编写了“我遇到以下错误”,但错误在哪里?看起来java无法找到
.dll
文件。尝试将其放入执行类文件的目录中。@SubodhJoshi我是cpp新手。我应该添加哪个
.dll
文件?
jniLegacyLibrary.dll
您也在使用Visual Studio吗?@SubodhJoshi否。我正在使用nodepad++编辑您编写的cpp代码“我遇到以下错误”,但错误在哪里?看起来java无法找到
.dll
文件。尝试将其放入执行类文件的目录中。@SubodhJoshi我是cpp新手。我要添加哪个
.dll
文件?
jniLegacyLibrary.dll
您也在使用Visual Studio吗?@SubodhJoshi否。我正在使用nodepad++编辑cpp代码
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());
    }
}