1

With JVMTI I am developing an agent to profile Java applications. Therefore a shared library libagent.so is compiled. Further I use the Qt framework:

For now it consists only by these two source files: agent.cpp and agentserver.cpp

However, when starting a Java application with my shared library libagent.so I get the error: undefined symbol: _ZTV11AgentServer (./libagent.so)

When I run ldd I get the same dependency problem:

ldd -d libagent.so 
linux-vdso.so.1 =>  (0x00007fffeb333000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f8b6731b000)
libm.so.6 => /lib/libm.so.6 (0x00007f8b67098000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007f8b66e81000)
libc.so.6 => /lib/libc.so.6 (0x00007f8b66afe000)
/lib64/ld-linux-x86-64.so.2 (0x00007f8b67844000)
undefined symbol: _ZTV11AgentServer (./libagent.so)

My current compile command is:

g++ $(CXXFLAGS) -fPIC -shared -o libagent.so $(INCPATH) ../src/agent.cpp ../src/agentserver.cpp

Where $(CXXFLAGS) is -m64 -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES)

where $(DEFINES) is -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED

where $(INCPATH) is -I/home/konrad/qtsdk-2010.05/qt/mkspecs/linux-g++-64 -I../src -I/home/konrad/qtsdk-2010.05/qt/include/QtCore -I/home/konrad/qtsdk-2010.05/qt/include/QtNetwork -I/home/konrad/qtsdk-2010.05/qt/include/QtGui -I/home/konrad/qtsdk-2010.05/qt/include -I/usr/lib/jvm/java-6-openjdk/include -I/usr/lib/jvm/java-6-openjdk/include/linux -I. -I. -I../src -I.

I have put some time into researching this problems, but none solved this error.


This is the header code of the agentserver.cpp: agentserver.h

eh9
  • 7,340
  • 20
  • 43
Konrad Reiche
  • 27,743
  • 15
  • 106
  • 143

1 Answers1

1

The error message is telling you that some element in AgentServer's vtable is undefined. The use of Q_OBJECT requires you to run moc on your source - and link to the qt libraries.

Erik
  • 88,732
  • 13
  • 198
  • 189
  • I declared only the constructor in the header file and I implemented it, as seen in the source code of agentserver.cpp:6-9 – Konrad Reiche Mar 20 '11 at 11:26
  • @platzhirsch: Post your header files – Erik Mar 20 '11 at 11:27
  • @Erik: Okay, the link to it is attached in my original post – Konrad Reiche Mar 20 '11 at 11:30
  • @platzhirsch: You'll need to run moc – Erik Mar 20 '11 at 11:34
  • @Erik: As I use the Qt IDE (qmake) the moc files are generated anyway. I can easily add the needed moc...cpp files, but how do I link to the Qt library? – Konrad Reiche Mar 20 '11 at 16:35
  • Pass `-lQtNetwork -lQtCore` to the g++ command - and add `-L/lib/path` – Erik Mar 20 '11 at 16:37
  • @Erik: But the Qt libraries Network and core are already included as seen in the definition of $(INCPATH) in my original post or is there a difference? – Konrad Reiche Mar 20 '11 at 16:44
  • Included header files declare that functions/classes/variables exist - you need to also link to the libraries that provide the declared symbols. – Erik Mar 20 '11 at 16:46
  • @Erik: Thank you, the problem is almost solved. Two dependencies remain: _ZN11AgentSErver18incomingConnectionEi and _ZN18AgentServerHandler3runEv although I included the moc*.cpp files, any idea? – Konrad Reiche Mar 20 '11 at 20:12
  • Are the two functions actually defined and not just declared in the header? – Erik Mar 20 '11 at 20:13
  • @Erik: They are both defined and declared. Is there more to include but moc_agentserver.cpp and moc_agentserverhandler.cpp ? – Konrad Reiche Mar 20 '11 at 20:19
  • @Erik: http://pastebin.com/U2uQbMpK (AgentServerHandler.h) http://pastebin.com/upmryC45 (AgentServerHandler.cpp) http://pastebin.com/iYDshsS1 (AgentServer.h) http://pastebin.com/LyEGmy48 (AgentServer.cpp) – Konrad Reiche Mar 20 '11 at 20:25
  • @platzhirsch: You need to link both the original .cpp's and the moc_*.cpp's – Erik Mar 20 '11 at 20:36
  • Thank you for your systematically help. It is fixed now. – Konrad Reiche Mar 20 '11 at 20:52