我正在尝试使用visual studio创建一个dll文件,并在java项目中使用/访问它.库似乎被加载,但总是抛出相同的异常:线程"main"中的异常java.lang.UnsatisfiedLinkError:查找函数'function'时出错:找不到指定的过程.我的C/C++技能不是最好的,所以问题就在那里.我尝试编辑h和cpp文件,使用类,命名空间,静态方法和Web上的其他人员,但无所事事.我还看到其他帖子谈论Depency Walker Tool,但它无法打开我的dll,我也看到编译器在函数名称中添加了一些奇怪的后缀,因为我知道可以通过使用"estern"来避免它h或cpp文件中的"C",但我无法使用.
我的界面:
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();
}
Run Code Online (Sandbox Code Playgroud)
我的主要课程:
public class Test_Dll {
public static void main(String[] args) {
SimpleDll simpleDll = SimpleDll.instance;
simpleDll.function();
}
}
Run Code Online (Sandbox Code Playgroud)
我的文件:
#ifndef SIMPLEDLL
#define SIMPLEDLL
namespace simpeDll{
static void function();
}
#endif
Run Code Online (Sandbox Code Playgroud)
我的cpp文件:
#include "stdafx.h"
#include "simpleDll.h"
#include <stdexcept>
using namespace simpeDll;
static void function(){
}
Run Code Online (Sandbox Code Playgroud)