Results 1 to 4 of 4

Thread: SOLVED: CMake link errors (A.K.A .moc handling)

  1. #1
    Join Date
    Jan 2008
    Posts
    107
    Thanks
    36
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question SOLVED: CMake link errors (A.K.A .moc handling)

    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 :

    Qt Code:
    1. project(teltonika_tcp_server3_garmin_support)
    2. cmake_minimum_required(VERSION 2.6)
    3. find_package(Qt4 REQUIRED)
    4.  
    5. include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})
    6.  
    7. set(teltonika_tcp_server3_garmin_support_SRCS crc_utils.cpp garmin_utils.cpp main.cpp server.cpp teltonikaunit.cpp)
    8. set(teltonika_tcp_server3_garmin_support_MOC_HDRS crc16.h crc_utils.h garmin.h garmin_utils.h properties.h server.h teltonikaunit.h)
    9.  
    10. add_definitions(-DQT_THREAD_SUPPORT)
    11.  
    12. qt4_wrap_cpp(teltonika_tcp_server3_garmin_support ${teltonika_tcp_server3_garmin_support_MOC_HDRS})
    13.  
    14. #qt4_automoc(${teltonika_tcp_server3_garmin_support_SRCS})
    15.  
    16. add_executable(teltonika_tcp_server3_garmin_support ${teltonika_tcp_server3_garmin_support_SRCS})
    17. target_link_libraries(teltonika_tcp_server3_garmin_support ${QT_QTCORE_LIBRARY} ${QT_QTNETWORK_LIBRARY} ${QT_QTSQL_LIBRARY})
    To copy to clipboard, switch view to plain text mode 

    On the linker phase I get this:

    Qt Code:
    1. CMakeFiles/teltonika_tcp_server3_garmin_support.dir/main.cpp.o: In function `main':
    2. main.cpp:(.text+0x741): undefined reference to `vtable for Server'
    3. main.cpp:(.text+0x922): undefined reference to `vtable for Server'
    4. CMakeFiles/teltonika_tcp_server3_garmin_support.dir/server.cpp.o: In function `Server::Server(QObject*)':
    5. server.cpp:(.text+0xab): undefined reference to `vtable for Server'
    6. CMakeFiles/teltonika_tcp_server3_garmin_support.dir/teltonikaunit.cpp.o: In function `TeltonikaThread::TeltonikaThread(int)':
    7. teltonikaunit.cpp:(.text+0x9f4): undefined reference to `vtable for TeltonikaThread'
    8. CMakeFiles/teltonika_tcp_server3_garmin_support.dir/teltonikaunit.cpp.o: In function `TeltonikaUnit::~TeltonikaUnit()':
    9. teltonikaunit.cpp:(.text+0xb2f8): undefined reference to `vtable for TeltonikaUnit'
    10. CMakeFiles/teltonika_tcp_server3_garmin_support.dir/teltonikaunit.cpp.o: In function `TeltonikaUnit::TeltonikaUnit(int)':
    11. teltonikaunit.cpp:(.text+0xdd97): undefined reference to `vtable for TeltonikaUnit'
    12. teltonikaunit.cpp:(.text+0xde2a): undefined reference to `TeltonikaUnit::error(QAbstractSocket::SocketError)'
    13. CMakeFiles/teltonika_tcp_server3_garmin_support.dir/teltonikaunit.cpp.o: In function `TeltonikaUnit::disconnected()':
    14. teltonikaunit.cpp:(.text+0x9c8): undefined reference to `TeltonikaUnit::quit()'
    15. CMakeFiles/teltonika_tcp_server3_garmin_support.dir/teltonikaunit.cpp.o: In function `TeltonikaUnit::forceDisconnect()':
    16. teltonikaunit.cpp:(.text+0xa95): undefined reference to `TeltonikaUnit::quit()'
    17. CMakeFiles/teltonika_tcp_server3_garmin_support.dir/teltonikaunit.cpp.o: In function `TeltonikaUnit::checkConnection()':
    18. teltonikaunit.cpp:(.text+0x14a00): undefined reference to `TeltonikaUnit::quit()'
    19. collect2: ld returned 1 exit status
    To copy to clipboard, switch view to plain text mode 

    Searching the project's tree I see that no .moc files are being created!
    I assumed that this line
    Qt Code:
    1. qt4_wrap_cpp(teltonika_tcp_server3_garmin_support ${teltonika_tcp_server3_garmin_support_MOC_HDRS})
    To copy to clipboard, switch view to plain text mode 

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

    I'm lost here and would really appreciate any help

    Best regards,
    Pedro Doria Meunier
    Last edited by pdoria; 6th June 2010 at 16:28. Reason: SOLVED

  2. #2
    Join Date
    Jan 2008
    Posts
    107
    Thanks
    36
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Lightbulb SOLVED: CMake link errors (A.K.A .moc handling)

    well replying to myself...

    this is how the problem was solved in CMakeLists.txt :
    Qt Code:
    1. project(teltonika_tcp_server3_garmin_support)
    2. cmake_minimum_required(VERSION 2.6)
    3. find_package(Qt4 REQUIRED)
    4.  
    5. include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})
    6.  
    7. set(teltonika_tcp_server3_garmin_support_SRCS crc_utils.cpp garmin_utils.cpp main.cpp server.cpp teltonikaunit.cpp)
    8. set(teltonika_tcp_server3_garmin_support_MOC_HDRS crc16.h crc_utils.h garmin.h garmin_utils.h properties.h server.h teltonikaunit.h)
    9.  
    10. add_definitions(-DQT_THREAD_SUPPORT)
    11.  
    12. qt4_wrap_cpp(teltonika_tcp_server3_garmin_support_CPP_FILES ${teltonika_tcp_server3_garmin_support_MOC_HDRS})
    13.  
    14. add_executable(teltonika_tcp_server3_garmin_support ${teltonika_tcp_server3_garmin_support_SRCS} ${teltonika_tcp_server3_garmin_support_CPP_FILES})
    15. target_link_libraries(teltonika_tcp_server3_garmin_support ${QT_QTCORE_LIBRARY} ${QT_QTNETWORK_LIBRARY} ${QT_QTSQL_LIBRARY})
    To copy to clipboard, switch view to plain text mode 

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

  3. #3
    Join Date
    Jul 2012
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: SOLVED: CMake link errors (A.K.A .moc handling)

    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.

  4. #4
    Join Date
    May 2012
    Posts
    28
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: SOLVED: CMake link errors (A.K.A .moc handling)


    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?

Similar Threads

  1. Static Qt+Webkit 4.6.2 Link Errors
    By geekox86 in forum Installation and Deployment
    Replies: 3
    Last Post: 20th June 2010, 05:06
  2. QCreator - undefined reference link errors
    By stodge in forum Newbie
    Replies: 2
    Last Post: 5th April 2009, 14:07
  3. Link errors for plugin under windows
    By QPlace in forum Qt Programming
    Replies: 5
    Last Post: 2nd November 2008, 15:51
  4. Q_OBJECT macro and link errors
    By pscheven in forum Qt Programming
    Replies: 4
    Last Post: 21st March 2008, 13:23
  5. Link Errors
    By magikalpnoi in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 22:04

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.