Cmake Qt5 | undefined reference to `QPrinter::QPrinter(QPrinter::PrinterMode)

后端 未结 1 1798
盖世英雄少女心
盖世英雄少女心 2021-01-15 12:49

I am preparing cmake build for qt application. where I am using following structure ..

libMyApp which uses

SET(QT5_MODULES Widgets PrintSupport Netw         


        
相关标签:
1条回答
  • 2021-01-15 13:34

    The order of the entries in the function TARGET_LINK_LIBRARIES() is important. The libraries with no dependecies shall be mentioned last which are typically some standard libraries or external libraries, in this example the Qt5 Libs.

    An example:

    • Application depends
    • Lib_A depends on Lib_B and Lib_std
    • Lib_B depends on Lib_std
    • Lib_std has no dependencies

    Then the call of the function shall be the following:

    TARGET_LINK_LIBRARIES(
        ${TARGET_NAME}   # Name of the app
        "Lib_A"
        "Lib_B"
        "Lib_std"        # Last entries: Std Libs, external Libs, ...
    )
    

    In this application I assumed that ${CODE_LIB_FILES}=libMyApp.a has some dependencies to the Qt5-Libs so it would be plausible to move this entry above the Qt5-Libs.

    SET(QT5_MODULES Widgets PrintSupport XmlPatterns)
    FIND_PACKAGE(Qt5 REQUIRED COMPONENTS ${QT5_MODULES})
    
    TARGET_LINK_LIBRARIES(
        ${TARGET_NAME}
        ${CODE_LIB_FILES}       # <<< Moved this entry up
        Qt5::Widgets
        Qt5::PrintSupport 
        Qt5::XmlPatterns
    )
    
    0 讨论(0)
提交回复
热议问题