【发布时间】:2015-09-16 10:25:45
【问题描述】:
我为 Java 编写了一个代理,它什么都不做,只导出两个方法,只是为了检查它是否在 JVM 启动时加载。使用 mingw-w64 4.8.4(使用 JetBrains CLion)构建它。 Windows 7 x64。
JNIEXPORT jint JNICALL
Agent_OnLoad(JavaVM *jvm, char *options, void *reserved){
return JNI_OK;
}
JNIEXPORT void JNICALL
Agent_OnUnload(JavaVM *vm){}
运行时出错
java -agentlib:"C:\JMVAgent\agent.dll"
Error occurred during initialization of VM
Could not find agent library libSampleAgent.dll on the library path,
with error: Can't find dependent libraries
我还将 agent.dll 放入 c:\windows\System32 并运行 java w/o agent full path 得到相同的结果。
请帮忙找出我做错了什么
【问题讨论】:
-
你是如何编译 .dll 的?请注意,如果您要指定代理库的完整路径,请使用
-agentpath而不是-agentlib。 -
我不明白你关于编译的问题,你对什么感兴趣? -agentpath 有帮助,非常感谢!
-
我的意思是命令行,你是如何从源代码构建 .dll 的。但是没关系。既然
agentpath解决了这个问题,我就把这个作为答案。