java.lang.UnsatisfiedLinkError: no jniLegacyLibrary in java.library.path

亡梦爱人 提交于 2019-12-14 02:51:20

问题


I am using javacpp to access cpp from Java.

I have tried the example provided in the documentation

cpp code:

#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 code:

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());
    }
}

My Folder structure in eclipse

I am getting following error if I run LegacyLibrary.java file in Eclipse

Exception in thread "main" java.lang.UnsatisfiedLinkError: no jniLegacyLibrary in java.library.path at java.lang.ClassLoader.loadLibrary(Unknown Source) at java.lang.Runtime.loadLibrary0(Unknown Source) at java.lang.System.loadLibrary(Unknown Source) at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:550) at org.bytedeco.javacpp.Loader.load(Loader.java:415) at org.bytedeco.javacpp.Loader.load(Loader.java:358) at LegacyLibrary$LegacyClass.(LegacyLibrary.java:8) at LegacyLibrary.main(LegacyLibrary.java:22)

What is wrong with my code?

来源:https://stackoverflow.com/questions/31824161/java-lang-unsatisfiedlinkerror-no-jnilegacylibrary-in-java-library-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!