Reputation: 105
I am coding a Java Agent library. However, the JVM cannot find Agent_OnLoad
function even if I have explicitly exported it in my C++ code.
JNIEXPORT jint JNICALL
Agent_OnLoad(JavaVM* vm, char* options, void* reserved)
{
return JNI_OK;
}
It then says Could not find Agent_OnLoad function in the agent library: ./FuncTest.dll
. The start-up command line is java -agentpath:./FuncTest.dll -jar .\helloworld.jar
Using Visual Studio 2022, Corretto 17.0.8
Upvotes: 0
Views: 272
Reputation: 105
Name decoration is applied to the exported function name.
By editing it to
extern "C" {
JNIEXPORT jint JNICALL
Agent_OnLoad(JavaVM* vm, char* options, void* reserved)
{
return JNI_OK;
}
}
solves the problem.
See How to specify a "clean" name of DLL exports? for a detailed answer.
Upvotes: 1