3

我正在尝试使用 Visual Studio 创建一个 dll 文件并在 Java 项目中使用/访问它。该库似乎已加载,但总是抛出相同的异常:线程“主”java.lang.UnsatisfiedLinkError 中的异常:查找函数“函数”时出错:找不到指定的过程。我的 C/C++ 技能不是最好的,所以问题可能就在那里。我尝试使用网上找到的类、命名空间、静态方法和其他人员来编辑 h 和 cpp 文件,但无事可做。我还看到其他关于 Depency Walker Tool 的帖子,但它无法打开我的 dll,我还看到编译器在函数名称中添加了一些奇怪的后缀,因为我知道可以通过使用“estern”来避免它'C'”在 h 或 cpp 文件中,但我做不到。

我的界面:

import com.sun.jna.Library;
import com.sun.jna.Native;

public interface SimpleDll extends Library {

    SimpleDll instance = (SimpleDll) Native.loadLibrary("SimpleDll", SimpleDll.class);

    void function();


}

我的主要课程:

public class Test_Dll {

    public static void main(String[] args) {
        SimpleDll simpleDll = SimpleDll.instance;

        simpleDll.function();
    }
}

我的 h 文件:

#ifndef SIMPLEDLL
#define SIMPLEDLL

namespace simpeDll{


    static void function();


}
#endif

我的 cpp 文件:

#include "stdafx.h"
#include "simpleDll.h"
#include <stdexcept>

using namespace simpeDll;

static void function(){

}
4

1 回答 1

7
  1. 确保在simpleDll命名空间之外声明你的函数。
  2. 确保用/装饰它extern "C"
  3. 确保公开您的功能__declspec(dllexport) void __cdecl function();或使用模块定义文件
于 2013-03-14T09:45:23.907 回答