PDA

View Full Version : SOLVED: CMake link errors (A.K.A .moc handling)



pdoria
6th June 2010, 14:55
Hi guys! :)
I'm back after a long time just to "bug" you with my problems with migration from qmake to cmake (namely from Kdev3 to Kdev4) ...

This is my CMakeLists.txt :


project(teltonika_tcp_server3_garmin_support)
cmake_minimum_required(VERSION 2.6)
find_package(Qt4 REQUIRED)

include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})

set(teltonika_tcp_server3_garmin_support_SRCS crc_utils.cpp garmin_utils.cpp main.cpp server.cpp teltonikaunit.cpp)
set(teltonika_tcp_server3_garmin_support_MOC_HDRS crc16.h crc_utils.h garmin.h garmin_utils.h properties.h server.h teltonikaunit.h)

add_definitions(-DQT_THREAD_SUPPORT)

qt4_wrap_cpp(teltonika_tcp_server3_garmin_support ${teltonika_tcp_server3_garmin_support_MOC_HDRS})

#qt4_automoc(${teltonika_tcp_server3_garmin_suppor t_SRCS})

add_executable(teltonika_tcp_server3_garmin_suppor t ${teltonika_tcp_server3_garmin_support_SRCS})
target_link_libraries(teltonika_tcp_server3_garmin _support ${QT_QTCORE_LIBRARY} ${QT_QTNETWORK_LIBRARY} ${QT_QTSQL_LIBRARY})

On the linker phase I get this:


CMakeFiles/teltonika_tcp_server3_garmin_support.dir/main.cpp.o: In function `main':
main.cpp:(.text+0x741): undefined reference to `vtable for Server'
main.cpp:(.text+0x922): undefined reference to `vtable for Server'
CMakeFiles/teltonika_tcp_server3_garmin_support.dir/server.cpp.o: In function `Server::Server(QObject*)':
server.cpp:(.text+0xab): undefined reference to `vtable for Server'
CMakeFiles/teltonika_tcp_server3_garmin_support.dir/teltonikaunit.cpp.o: In function `TeltonikaThread::TeltonikaThread(int)':
teltonikaunit.cpp:(.text+0x9f4): undefined reference to `vtable for TeltonikaThread'
CMakeFiles/teltonika_tcp_server3_garmin_support.dir/teltonikaunit.cpp.o: In function `TeltonikaUnit::~TeltonikaUnit()':
teltonikaunit.cpp:(.text+0xb2f8): undefined reference to `vtable for TeltonikaUnit'
CMakeFiles/teltonika_tcp_server3_garmin_support.dir/teltonikaunit.cpp.o: In function `TeltonikaUnit::TeltonikaUnit(int)':
teltonikaunit.cpp:(.text+0xdd97): undefined reference to `vtable for TeltonikaUnit'
teltonikaunit.cpp:(.text+0xde2a): undefined reference to `TeltonikaUnit::error(QAbstractSocket::SocketError )'
CMakeFiles/teltonika_tcp_server3_garmin_support.dir/teltonikaunit.cpp.o: In function `TeltonikaUnit::disconnected()':
teltonikaunit.cpp:(.text+0x9c8): undefined reference to `TeltonikaUnit::quit()'
CMakeFiles/teltonika_tcp_server3_garmin_support.dir/teltonikaunit.cpp.o: In function `TeltonikaUnit::forceDisconnect()':
teltonikaunit.cpp:(.text+0xa95): undefined reference to `TeltonikaUnit::quit()'
CMakeFiles/teltonika_tcp_server3_garmin_support.dir/teltonikaunit.cpp.o: In function `TeltonikaUnit::checkConnection()':
teltonikaunit.cpp:(.text+0x14a00): undefined reference to `TeltonikaUnit::quit()'
collect2: ld returned 1 exit status

Searching the project's tree I see that no .moc files are being created! :confused:
I assumed that this line

qt4_wrap_cpp(teltonika_tcp_server3_garmin_support ${teltonika_tcp_server3_garmin_support_MOC_HDRS})

would take care of business (as per much googling...) :confused:

I'm lost here and would really appreciate any help ;)

Best regards,
Pedro Doria Meunier

pdoria
6th June 2010, 16:26
well replying to myself... :cool:

this is how the problem was solved in CMakeLists.txt :


project(teltonika_tcp_server3_garmin_support)
cmake_minimum_required(VERSION 2.6)
find_package(Qt4 REQUIRED)

include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})

set(teltonika_tcp_server3_garmin_support_SRCS crc_utils.cpp garmin_utils.cpp main.cpp server.cpp teltonikaunit.cpp)
set(teltonika_tcp_server3_garmin_support_MOC_HDRS crc16.h crc_utils.h garmin.h garmin_utils.h properties.h server.h teltonikaunit.h)

add_definitions(-DQT_THREAD_SUPPORT)

qt4_wrap_cpp(teltonika_tcp_server3_garmin_support_ CPP_FILES ${teltonika_tcp_server3_garmin_support_MOC_HDRS})

add_executable(teltonika_tcp_server3_garmin_suppor t ${teltonika_tcp_server3_garmin_support_SRCS} ${teltonika_tcp_server3_garmin_support_CPP_FILES})
target_link_libraries(teltonika_tcp_server3_garmin _support ${QT_QTCORE_LIBRARY} ${QT_QTNETWORK_LIBRARY} ${QT_QTSQL_LIBRARY})

Hope this helps another poor wretch (a.k.a. cmake newbie) like me to overcome linking errors.. ;)

Daneel Olivaw
6th July 2012, 16:42
Well, I know I am 2 years too late for this but I figured some poor wretch like me too would get help on this.
Ironically, I came across this post AFTER I solved my problem.
I had the same problem of "undefined vtable reference" and the most common error which results in this error is that you have not defined the constructors/destructors or any virtual functions.
The mistake that I did was I did not set the headers with QOBJECT macros and wrap them with qt4_wrap_cpp. This gave the undefined vtable reference error.
So, if you have QOBJECT macro in a filled Launcher.h, make sure you do this in your CMakeLists.txt :


SET(QtTest_HDRS ${QtTest_HDRS} Launcher.h)

QT4_WRAP_CPP(QtTest_HDRS_MOC ${QtTest_HDRS})


I wish I had found this thread earlier. Now I hope this will help someone.

mchome
18th July 2012, 13:38
I have, I think, the same problem as Daneel, but I don't understand his answer.
I program using Qt Creator, that does not involve any CMakeLists.txt, AFAIK.
More precisely I use Qt creator 2.4.1 and Qt 4.8.1 in an Apple system, along with GCC compiler.

I have created a program that works well, and does not make use of signals/slots yet, but I plan to introduce them now.
Just adding the Q_OBJECT macro causes the following error message:

:-1: error: symbol(s) not found for architecture x86_64
:-1: error: collect2: ld returned 1 exit status

that corresponds to the following problems shown in the Compile Output:

Undefined symbols for architecture x86_64:
"vtable for CLineChart", referenced from:
CLineChart::CLineChart(QWidget*)in clinechart.o
CLineChart::CLineChart(QWidget*)in clinechart.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"CLineChart::staticMetaObject", referenced from:
CLineChart::tr(char const*, char const*)in clinechart.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [TestLisneChart.app/Contents/MacOS/TestLisneChart] Error 1

Does someone have any suggestion for me?