mtrace.c compilation and dll load
Hi, I am currently trying to instrument a Java class with module calls to a Monitor and some state variables. So I have been trying to play with the mtrace.c provided in the demo section of the jdk download. Initially, there was the "opcode.h" not found ( which was spoken to about in the past topics and was resolved consequently in the next update, 9 ).
Now, everything works great when I use the provided dll. But when I try to create my own dll using the following -
C:\>gcc -Wall -D_JNI_IMPLEMENTATION_ -Ic:/jdk1.5.0_09/include -Ic:/jdk1.5.0_09/include/win32 -shared -c mtrace.c
C:\>gcc -Wall -D_JNI_IMPLEMENTATION_ -Ic:/jdk1.5.0_09/include -Ic:/jdk1.5.0_09/include/win32 -shared -c java_crw_demo.c
then , gcc java_crw_demo.o mtrace.o -o something.dll
I get, "undefined reference to" fatal_error , std_out and get_token . Even with gcc option -Ljava_crw_demo ( a dll made from java_crw_demo.*) , I get the same errors.
Is there something missing from my compilation procedure ? Or is it a mistake like the last times "opcode.h" reference ?
Additionally, it should be noted that java_crw_demo.c has fatal_error module declared as static.
Please let me know how I could resolve this.
[1254 byte] By [
grokmenowa] at [2007-10-3 6:57:10]

Let me correct the above post. I realized my mistake. I wasnt using agent_util for my compilation.
So, heres an update -
C:\test> gcc -Wall -D_JNI_IMPLEMENTATION_ -Ic:/jdk1.5.0_09/include -Ic:/jdk1.5.
0_09/include/win32 -shared -c mtrace.c
C:\test> gcc -Wall -D_JNI_IMPLEMENTATION_ -Ic:/jdk1.5.0_09/include -Ic:/jdk1.5.
0_09/include/win32 -shared -c agent_util.c
C:\test> gcc -Wall -D_JNI_IMPLEMENTATION_ -Ic:/jdk1.5.0_09/include -Ic:/jdk1.5.
0_09/include/win32 -shared -c java_crw_demo.c
C:\test>gcc -shared -o something.dll -static-libgcc -mimpure-text java_crw_demo.
o
C:\test>gcc -shared -o mtrace.dll -static-libgcc -mimpure-text -L./ -lsomething
mtrace.o agent_util.o
so, everything works great until here.
But when I do a
java -Xbootclasspath/a:mtrace.jar -agentlib:mtrace
I get,
Error occurred during initialization of VM
Could not find Agent_OnLoad function in the agent library: mtrace
Am I performing any of the above compilations incorrectly?
PS - I have crossed checked all the .c and .h files involved.
Hi, actually now I am getting no errors ( except for a small implementation problem also posted on the forum).
I cant really recall what the problem was, but just cross checking and making sure that your make file runs properly ( the make file is for specific compilers depending on the OS) and once you include them in the local directory and run
java -Xbootclasspath/a:mtrace.jar -agentlib:mtrace , it runs perfectly.
Also, what i noticed ( maybe it was metioned somewhere, but I couldnt find it) was if you wan to include many different packagaes, you can instead do
java -Xbootclasspath/a:mtrace.jar:ltl2ba4j.jar etc. etc. So, at the end of it, I had a pretty long jar inclusion in the Xbootlcasspath agent list...and everyworked seamlessly. Are you continuing to get the same errors?
My first and most important suggestion is working with the Makefile. This changed everything for me....
with regards
vaishak Belle