Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Default QtCreator QML Quick Controls Project Fails To Link



  • I have been trying for a little bit to get a QML Quick Controls 2 project to build for iOS using CMake. Everything seems to build just fine, but the link step fails. The errors can be seen on my pastbin post:
    https://pastebin.com/Mm07v7k1

    I know QML can compile and link for iOS (both a device and simulator) because I can use QtCreator to build the QML Gallery example: https://doc.qt.io/qt-5.10/qtquickcontrols2-gallery-example.html with no issues.

    Even empty QtCreator generated projects utilizing CMake do not build to completion, so I thought I would ask here for help.

    I suspect it has something to do with linking and importing the appropriate plugins that come packaged with Qt.

    Here are my files for reference.

    # CMakeLists.txt
    cmake_minimum_required(
        VERSION
            3.7.1
    )
    
    project(
        QMLGallery
    )
    
    find_package(Qt5Core REQUIRED)
    find_package(Qt5Gui REQUIRED)
    find_package(Qt5Widgets REQUIRED)
    find_package(Qt5Quick REQUIRED)
    find_package(Qt5Qml REQUIRED)
    find_package(Qt5QuickControls2 REQUIRED)
    
    ######################################################################
    find_library(
        Qt5Quick2Plugin
        NAMES
            libqtquick2plugin.a
        HINTS
            /Users/daddymac/Qt/5.10.1/ios/qml/QtQuick.2
    )
    
    find_library(
        Qt5QuickControls2Plugin
        NAMES
            libqtquickcontrols2plugin.a
        HINTS
            /Users/daddymac/Qt/5.10.1/ios/qml/QtQuick/Controls.2
    )
    
    find_library(
        Qt5QuickTemplates2Plugin
        NAMES
            libqtquicktemplates2plugin.a
        HINTS
            /Users/daddymac/Qt/5.10.1/ios/qml/QtQuick/Templates.2
    )
    
    find_library(
        Qt5QuickWindow2Plugin
        NAMES
            libwindowplugin.a
        HINTS
            /Users/daddymac/Qt/5.10.1/ios/qml/QtQuick/Window.2
    )
    
    find_library(
        Qt5QuickControls2MaterialStylePlugin
        NAMES
            libqtquickcontrols2materialstyleplugin.a
        HINTS
            /Users/daddymac/Qt/5.10.1/ios/qml/QtQuick/Controls.2/Material
    )
    
    find_library(
        Qt5QuickControls2UniversalStylePlugin
        NAMES
            libqtquickcontrols2Universalstyleplugin.a
        HINTS
            /Users/daddymac/Qt/5.10.1/ios/qml/QtQuick/Controls.2/Universal
    )
    
    find_library(
        Qt5QMLSettingsPlugin
        NAMES
            libqmlsettingsplugin.a
        HINTS
            /Users/daddymac/Qt/5.10.1/ios/qml/Qt/labs/settings
    )
    
    find_library(
        Qt5IOSPlatformPlugin
        NAMES
            libqios.a
        HINTS
            /Users/daddymac/Qt/5.10.1/ios/plugins/platforms
    )
    
    ###########################
    
    find_library(
        Qt5Quick2PluginD
        NAMES
            libqtquick2plugin_debug.a
        HINTS
            /Users/daddymac/Qt/5.10.1/ios/qml/QtQuick.2
    )
    
    find_library(
        Qt5QuickControls2PluginD
        NAMES
            libqtquickcontrols2plugin_debug.a
        HINTS
            /Users/daddymac/Qt/5.10.1/ios/qml/QtQuick/Controls.2
    )
    
    find_library(
        Qt5QuickTemplates2PluginD
        NAMES
            libqtquicktemplates2plugin_debug.a
        HINTS
            /Users/daddymac/Qt/5.10.1/ios/qml/QtQuick/Templates.2
    )
    
    find_library(
        Qt5QuickWindow2PluginD
        NAMES
            libwindowplugin_debug.a
        HINTS
            /Users/daddymac/Qt/5.10.1/ios/qml/QtQuick/Window.2
    )
    
    find_library(
        Qt5QuickControls2MaterialStylePluginD
        NAMES
            libqtquickcontrols2materialstyleplugin_debug.a
        HINTS
            /Users/daddymac/Qt/5.10.1/ios/qml/QtQuick/Controls.2/Material
    )
    
    find_library(
        Qt5QuickControls2UniversalStylePluginD
        NAMES
            libqtquickcontrols2Universalstyleplugin_debug.a
        HINTS
            /Users/daddymac/Qt/5.10.1/ios/qml/QtQuick/Controls.2/Universal
    )
    
    find_library(
        Qt5QMLSettingsPluginD
        NAMES
            libqmlsettingsplugin_debug.a
        HINTS
            /Users/daddymac/Qt/5.10.1/ios/qml/Qt/labs/settings
    )
    
    find_library(
        Qt5IOSPlatformPluginD
        NAMES
            libqios_debug.a
        HINTS
            /Users/daddymac/Qt/5.10.1/ios/plugins/platforms
    )
    
    ######################################################################
    
    set(CMAKE_INCLUDE_CURRENT_DIR "ON")
    set(CMAKE_AUTOMOC "ON")
    set(CMAKE_AUTORCC "ON")
    
    set(CMAKE_CXX_VERSION "11")
    
    
    # qt5_add_resources(
    #     RESOURCES
    #         ${CMAKE_CURRENT_SOURCE_DIR}/Resources.qrc
    #     OPTIONS --name Resources
        
    # )
    
    set(EXECUTABLE_TARGET
        "QMLGalleryApp"
    )
    
    set(
        DEFINITION_FILES
        ${CMAKE_CURRENT_SOURCE_DIR}/gallery.cpp
    )
    
    set(
        INCLUDE_PATHS
        ${CMAKE_CURRENT_SOURCE_DIR}
        ${Qt5Core_INCLUDE_DIRS}
        ${Qt5Widgets_INCLUDE_DIRS}
        ${Qt5Gui_INCLUDE_DIRS}
        ${Qt5Quick2_INCLUDE_DIRS}
        ${Qt5QuickControls2_INCLUDE_DIRS}
        /Users/daddymac/Qt/5.10.1/ios/mkspecs/common/uikit
    )
    
    set(
        LINK_TARGETS
        ${Qt5Core_LIBRARIES}
        ${Qt5Widgets_LIBRARIES}
        ${Qt5Gui_LIBRARIES}
        ${Qt5Quick2_LIBRARIES}
        ${Qt5QuickControls2_LIBRARIES}
        
        ${Qt5QMLSettingsPlugin}
        ${Qt5QuickControls2UniversalStylePlugin}
        ${Qt5QuickControls2MaterialStylePlugin}
        ${Qt5QuickWindow2Plugin}
        ${Qt5QuickTemplates2Plugin}
        ${Qt5QuickControls2Plugin}
        ${Qt5Quick2Plugin}
        ${Qt5IOSPlatformPlugin}
        
        ${Qt5QMLSettingsPluginD}
        ${Qt5QuickControls2UniversalStylePluginD}
        ${Qt5QuickControls2MaterialStylePluginD}
        ${Qt5QuickWindow2PluginD}
        ${Qt5QuickTemplates2PluginD}
        ${Qt5QuickControls2PluginD}
        ${Qt5Quick2PluginD}
        ${Qt5IOSPlatformPluginD}
    )
    
    ######################################################################
    
    add_executable(${EXECUTABLE_TARGET}
        ${DEFINITION_FILES}
    )
    
    target_include_directories(${EXECUTABLE_TARGET}
        PUBLIC
            ${INCLUDE_PATHS}
    }
    )
    
    target_link_libraries(${EXECUTABLE_TARGET}
        PUBLIC
            ${LINK_TARGETS}
    )
    

    The project itself is the gallery example I mentioned above. Any ideas what is causing the link issues?



  • Try find_package(Qt5QuickTemplates2 REQUIRED) and then adding ${Qt5QuickTemplates2_LIBRARIES} to LINK_TARGETS.



  • @jpnurmi said in Default QtCreator QML Quick Controls Project Fails To Link:

    Try find_package(Qt5QuickTemplates2 REQUIRED) and then adding ${Qt5QuickTemplates2_LIBRARIES} to LINK_TARGETS

    There is no Config.cmake files for Qt5Templates2. There is a plugin that I tried linking to as you can see in my CMakeLists.txt file. I also have the required Q_IMPORT_PLUGIN(QtQuickTemplates2Plugin); inside the gallery.cpp file.



  • The source code branch seems to package QQuickTemplates2 with QtQuickControls2, so I think those should be linking in.



  • Hmm, the missing symbols are in libQt5QuickTemplates2, not in libqtquicktemplates2plugin. As of today, the QtQuickTemplates2 library is indeed not public. I suppose Qt generates .cmake files only for public libraries. Sorry, I'm not using CMake with Qt so I don't know the exact details, but somehow you must get it to link with libQt5QuickTemplates2. :)



  • @jpnurmi

    Do you know where in a Qt installation that library would be located?



  • Together with other libs (not plugins). You can run qmake -query from a specific Qt installation. Something like:

    $ ~/Qt/5.10.1/ios/bin/qmake -query QT_INSTALL_LIBS
    /Users/daddymac/Qt/5.10.1/ios/lib
    
    $ ls /Users/daddymac/Qt/5.10.1/ios/lib
    [...]
    libQt5QuickTemplates2.a
    [...]


  • @jpnurmi
    I understand now. I still am getting link errors. Now it looks like there are definitions missing that are in the libpng (i.e. libqtlibpng.a)

    Is there some qmake query that I can run on a static library to get all of its dependent Qt libraries or something? Or even if I could run the query on a bare bones .pro project and see all of the resulting static libraries and their locations, I could probably resolve the link issues.



  • So I updated my CMakeLists.txt file to represent what is generated by qmake in QtCreator as far as the link and include items.

    cmake_minimum_required(
        VERSION
            3.7.1
    )
    
    project(
        QMLGallery
    )
    
    set(CMAKE_INCLUDE_CURRENT_DIR "ON")
    set(CMAKE_AUTOMOC "ON")
    set(CMAKE_AUTORCC "ON")
    
    set(EXECUTABLE_TARGET
        "QMLGalleryApp"
    )
    
    set(
        DEFINITION_FILES
        ${CMAKE_CURRENT_SOURCE_DIR}/gallery.cpp
    )
    
    set(
        INCLUDE_PATHS
        ${CMAKE_CURRENT_SOURCE_DIR}
        ${CMAKE_CURRENT_BINARY_DIR}
        /Users/daddymac/Qt/5.10.1/ios/mkspecs/common/uikit
        /Users/daddymac/Qt/5.10.1/ios/include
        /Users/daddymac/Qt/5.10.1/ios/include/QtQuickControls2
        /Users/daddymac/Qt/5.10.1/ios/include/QtQuick
        /Users/daddymac/Qt/5.10.1/ios/include/QtGui
        /Users/daddymac/Qt/5.10.1/ios/include/QtQml
        /Users/daddymac/Qt/5.10.1/ios/include/QtNetwork
        /Users/daddymac/Qt/5.10.1/ios/include/QtCore
        /Users/daddymac/Qt/5.10.1/ios/mkspecs/macx-ios-clang   
    )
    
    add_executable(${EXECUTABLE_TARGET}
        ${DEFINITION_FILES}
    )
    
    target_include_directories(${EXECUTABLE_TARGET}
        PUBLIC
            ${INCLUDE_PATHS}
    )
    
    macro(ADD_FRAMEWORK fwname appname path)
        find_library(FRAMEWORK_${fwname}
        NAMES ${fwname}
        PATHS ${path}
        NO_DEFAULT_PATH
        )
        
        if( ${FRAMEWORK_${fwname}} STREQUAL FRAMEWORK_${fwname}-NOTFOUND)
            MESSAGE(ERROR ": Framework ${fwname} not found")
        else()
            target_link_libraries(${appname} PUBLIC "${FRAMEWORK_${fwname}}/${fwname}")
            MESSAGE(STATUS "Framework ${fwname} found at ${FRAMEWORK_${fwname}}")
        endif()
    endmacro(ADD_FRAMEWORK)
    
    add_framework(
        Foundation
        ${EXECUTABLE_TARGET}
        /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks
    )
    
    add_framework(
        UIKit
        ${EXECUTABLE_TARGET}
        /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks
    )
    
    add_framework(
        QuartzCore
        ${EXECUTABLE_TARGET}
        /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks
    )
    
    add_framework(
        AudioToolbox
        ${EXECUTABLE_TARGET}
        /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks
    )
    
    add_framework(
        AssetsLibrary
        ${EXECUTABLE_TARGET}
        /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks
    )
    
    add_framework(
        MobileCoreServices
        ${EXECUTABLE_TARGET}
        /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks
    )
    
    add_framework(
        CoreFoundation
        ${EXECUTABLE_TARGET}
        /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks
    )
    
    add_framework(
        CoreGraphics
        ${EXECUTABLE_TARGET}
        /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks
    )
    
    add_framework(
        OpenGLES
        ${EXECUTABLE_TARGET}
        /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks
    )
    
    add_framework(
        CoreText
        ${EXECUTABLE_TARGET}
        /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks
    )
    
    add_framework(
        ImageIO
        ${EXECUTABLE_TARGET}
        /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks
    )
    
    add_framework(
        Security
        ${EXECUTABLE_TARGET}
        /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks
    )
    
    target_link_libraries(${EXECUTABLE_TARGET}
        PUBLIC
        "-L/Users/daddymac/Qt/5.10.1/ios/lib"
        "-L/Users/daddymac/Qt/5.10.1/ios/plugins/imageformats"
        "-L/Users/daddymac/Qt/5.10.1/ios/plugins/platforms"
        "-L/Users/daddymac/Qt/5.10.1/ios/plugins/qmltooling"
        "-L/Users/daddymac/Qt/5.10.1/ios/plugins/bearer"
        "-L/Users/daddymac/Qt/5.10.1/ios/qml/QtQuick.2"
        "-L/Users/daddymac/Qt/5.10.1/ios/qml/QtQuick/Layouts"
        "-L/Users/daddymac/Qt/5.10.1/ios/qml/QtQuick/Controls.2"
        "-L/Users/daddymac/Qt/5.10.1/ios/qml/QtQuick/Controls.2/Material"
        "-L/Users/daddymac/Qt/5.10.1/ios/qml/QtQuick/Controls.2/Universal"
        "-L/Users/daddymac/Qt/5.10.1/ios/qml/Qt/labs/settings"
        "-L/Users/daddymac/Qt/5.10.1/ios/qml/QtQuick/Templates.2"
        "-L/Users/daddymac/Qt/5.10.1/ios/qml/QtQuick/Window.2"
        "-lqios"
        "-lQt5FontDatabaseSupport"
        "-lqtfreetype"
        "-lQt5GraphicsSupport"
        "-lQt5ClipboardSupport"
        "-lqgif"
        "-lqicns"
        "-lqico"
        "-lqjpeg"
        "-lqmacjp2"
        "-lqtga"
        "-lqtiff"
        "-lqwbmp"
        "-lqwebp"
        "-lqmldbg_debugger"
        "-lqmldbg_inspector"
        "-lqmldbg_local"
        "-lqmldbg_messages"
        "-lqmldbg_native"
        "-lqmldbg_nativedebugger"
        "-lqmldbg_profiler"
        "-lqmldbg_quickprofiler"
        "-lqmldbg_server"
        "-lQt5PacketProtocol"
        "-lqmldbg_tcp"
        "-lqgenericbearer"
        "-lqtquick2plugin"
        "-lqquicklayoutsplugin"
        "-lqtquickcontrols2plugin"
        "-lqtquickcontrols2materialstyleplugin"
        "-lqtquickcontrols2universalstyleplugin"
        "-lQt5QuickControls2"
        "-lqmlsettingsplugin"
        "-lqtquicktemplates2plugin"
        "-lQt5QuickTemplates2"
        "-lwindowplugin"
        "-lQt5Quick"
        "-lQt5Qml"
        "-lQt5Gui"
        "-lqtlibpng"
        "-lqtharfbuzz"
        "-lQt5Network"
        "-lQt5Core"
        "-lm"
        "-lz"
        "-lqtpcre2"
    )
    

    A quick inspection looks like everything discussed so far has been included, but I am still getting reference errors.

    https://pastebin.com/7vLqcPeP



  • @Jman006

    Ok I made progress. This CMakeLists.txt is hardcoded for the iOS simulator. When I select the simulator in XCode, everything links properly. I still have a runtime error, but that is a different issue.

    I'm still working on getting the both simulator and actual hardware versions to build. I'll post back the results.


Log in to reply