0

I wrote an agent for Java which does nothing just exports two methods, just to check if it loaded on JVM start or not. Built it with mingw-w64 4.8.4 (using 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){}

Got an error running

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

Also I placed agent.dll into c:\windows\System32 and run java w/o agent full path with the same result.

DependencyWalker shows no dependency error enter image description here

Please help to find what I'm doing wrong

Ed Pavlov
  • 2,353
  • 2
  • 19
  • 25
  • 1
    How did you compile .dll? Note, if you are specifying full path to the agent library, use `-agentpath` instead of `-agentlib`. – apangin Sep 16 '15 at 11:09
  • I don't understand your question regard compiling, what exactly are you interested in? -agentpath helps, thanks a lot! – Ed Pavlov Sep 16 '15 at 12:52
  • I mean the command line, how did you build .dll from the source. But never mind. Since `agentpath` solves the problem, I'll make this an answer. – apangin Sep 16 '15 at 12:58

1 Answers1

5

If you with to specify the full path to the agent library, use -agentpath instead of -agentlib.

The difference is explained here.

apangin
  • 92,924
  • 10
  • 193
  • 247