Results 1 to 2 of 2

Thread: cmake moc undefined reference issue

  1. #1
    Join Date
    Jul 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default cmake moc undefined reference issue

    Hello,

    I am compiling a Qt based project using CMake. The target is a static library "myLib.a".
    Then when I compile an executable (always using CMake) that uses "myLib.a" I get undefined references:
    - On all the signals of moc'ed classes
    - On vtables of moc'ed classes

    The CMake logs show that the moc_***.cxx files:
    - Are generated (I am using the CMake command "qt4_wrap_cpp")
    - Are compiled in moc_***.cpp.o
    - Are linked to the static library "myLib.a"

    What can be wrong? Why aren't Qt stuff recognized?

    The relevant section of the CMake for "myLib.a":

    Qt Code:
    1. qt4_wrap_cpp(MOCS ${MOC_HDRS})
    2. add_library(myLib ${STATIC_OR_SHARED_FLAG} ${SRCS} ${MOCS})
    3. target_link_libraries(RegattaClientSDK $${QT_LIBRARIES})
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance for your help!

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: cmake moc undefined reference issue

    you're not linking your app correctly with your static library.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. CMake :Undefined reference for a QObject class
    By Zander87 in forum General Programming
    Replies: 2
    Last Post: 8th November 2012, 14:35
  2. Replies: 1
    Last Post: 5th February 2011, 03:04
  3. Undefined reference
    By eekhoorn12 in forum Qt Programming
    Replies: 2
    Last Post: 6th January 2011, 15:45
  4. undefined reference
    By jayreddy in forum Qt Programming
    Replies: 1
    Last Post: 20th November 2009, 13:45
  5. Undefined reference
    By Salazaar in forum Newbie
    Replies: 12
    Last Post: 23rd May 2007, 10:21

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.