java.lang.UnsatisfiedLinkError:LegacyLibrary $ LegacyClass.allocate()V

时间:2015-08-05 09:13:44

标签: java c++ javacpp

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

LegacyLibrary.h代码

#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;
    };
}

文件夹结构

enter image description here

enter image description here

我正在使用Javacpp来访问Java中的cpp函数。我正在尝试执行文档中给出的示例。我在Visual Studio 2013中构建了一个jniLegacyLibrary.dll并将其添加到目录中并在eclipse中执行了Java文件。

我收到以下错误。

  

线程“main”中的异常java.lang.UnsatisfiedLinkError:LegacyLibrary $ LegacyClass.allocate()V       在LegacyLibrary $ LegacyClass.allocate(本机方法)       在LegacyLibrary $ LegacyClass。(LegacyLibrary.java:9)       在LegacyLibrary.main(LegacyLibrary.java:22)

我对cpp很新。我的代码有什么问题?

0 个答案:

没有答案