JNI 不满意链接错误: 动态链接库 (DLL) 初始化例程失败
JNI UnsatisfiedLinkError: A dynamic link library (DLL) initialization routine failed
我正在尝试通过JNI从c ++调用函数。 我已经按照我在网上找到的说明进行操作,但仍然收到异常:
线程"main"java.lang.UnsatisfiedLinkError中的异常:\path\to\dll\remoteAPI.dll:动态链接库(DLL(初始化例程失败
DLL 文件的路径是正确的,它位于那里。 我通过IntelliJ中的VMOptions通过以下方式添加了路径:-Djava.library.path=\path\to\dll
那么为什么我仍然会收到异常呢?显然,当 DllMain 返回值 false 时会抛出此异常。但是我在这里需要一个还是有 jni 库一个,如果我需要实现它,我应该把它放在哪里?
entities_remoteAPI.h
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class entities_remoteAPI */
#ifndef _Included_entities_remoteAPI
#define _Included_entities_remoteAPI
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: entities_remoteAPI
* Method: sayHello
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_entities_remoteAPI_sayHello
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
entities_remoteAPI.cpp
#include <jni.h>
#include "entities_remoteAPI.h"
JNIEXPORT void JNICALL Java_entities_remoteAPI_sayHello
(JNIEnv* env, jobject thisObject) {
}
应用.java
public class App
{
public static void main( String[] args ) {
System.out.println( "Hello World!" );
System.loadLibrary("remoteAPI");
RemoteAPI ai = new RemoteAPI();
ai.sayHello();
}
}
entities/RemoteAPI.java
package entities;
public class RemoteAPI {
public native void sayHello();
}
我现在通过从命令行编译 dll 而不是使用 IDECode::Blocks来摆脱异常。 我使用的命令在哪里
g++ -c -I%JAVA_HOME%\include -I%JAVA_HOME%\include\win32 entities_RemoteAPI.cpp -o entities_RemoteAPI.o
和
g++ -shared -o remoteAPI.dll entities_RemoteAPI.o -Wl,--add-stdcall-alias
显然,它与构建DLL时的选项Code::Blocks传递有关。
相关文章:
- 视觉C++:在 DLL 加载期间,全局变量初始化顺序是否具有确定性?
- JNI 不满意链接错误: 动态链接库 (DLL) 初始化例程失败
- DLL – 在 DLL 初始化时填充的静态向量,向客户端程序返回零大小
- 如何初始化堆,以便静态构造函数可以在常规 MFC dll 中使用堆?
- 初始化 C# IntPtr 以接受来自非托管 C++ DLL 的数据?
- 在DLL中仅初始化变量一次
- 在 dll 中初始化记录器
- DLL 中的 C++ 静态局部变量初始化会导致_CrtIsValidHeapPointer异常
- 如何在托管dll中重新初始化本机代码
- 从c++调用matlab dll:初始化库失败
- Python 在主机程序初始化后连接到C++ dll?
- TheoraVideoManager不会在0x7329E13D(msvcr110.dll)处初始化未处理的异常
- 调用本机(DLL)代码从Java使用JNI保持变量c++初始化每个新的召回函数
- c++二进制兼容dll POD类成员初始化导致崩溃
- c++ DLL的制作:静态变量初始化问题
- 可以初始化dll文件吗?一个dll构造函数
- C++DLL中具有内置类型的静态变量未初始化
- Windows DLL用文件初始化常量c字符串数组
- 当使用Windows可执行文件作为DLL时,如何初始化C运行时
- 无法在c++中初始化Matlab dll