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

Qt5 CMake include all libraries into executable



  • I'm trying to build a with Qt 5.14 an application on release mode and everything is working fine inside of Qt Creator, but when I'm trying to run the executable by itself I'm getting an error like this:


    OS: Windows 10

    Qt: 5.14

    Cmake: 3.5


    enter image description here


    What I've tried:

    1. set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")
    2. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -fPIC")
    3. ${ADDITIONAL_LIBRARIES} -static inside of target_link_libraries

    None of the above worked for me and I'm getting the same error whenever I'm trying to run the executable by its self without using Qt Creator.


    My CMake file:

    cmake_minimum_required(VERSION 3.5)
    
    project(Scrollable LANGUAGES CXX)
    
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
    
    set(CMAKE_AUTOUIC ON)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    
    set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")
    set(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -std=c++0x -fPIC")
    set(CMAKE_CXX_STANDARD 14)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    find_package(Qt5 REQUIRED Core Widgets Gui Qml Quick Qml)
    
    qt5_add_resources(resource.qrc)
    
    include_directories(${CMAKE_CURRENT_SOURCE_DIR})
    include_directories("MoviesInterface")
    
    set(SOURCES
            main.cpp
            MovieInterface/movieinterfaceomdb.cpp
            MovieInterface/moviesinterface.cpp
            )
    
    set(HEADERS
            MovieInterface/movieinterfaceomdb.h
            MovieInterface/moviesinterface.h
            )
    
    
    add_executable(Scrollable ${SOURCES} ${HEADERS} qml.qrc)
    qt5_use_modules(Scrollable Core Network)
    target_link_libraries(Scrollable
            Qt5::Core
            Qt5::Gui
            Qt5::Widgets
            Qt5::Qml
            ${ADDITIONAL_LIBRARIES} -static
            )

  • Lifetime Qt Champion

    Hi,

    To execute your application outside of Qt Creator, you have to deploy it using windeployqt.


Log in to reply