Qt5 CMake将所有库包含到可执行文件中

问题描述 投票:0回答:1

[我正在尝试使用Qt 5.14在释放模式下构建一个应用程序,并且在Qt Creator中一切正常,但是当我尝试自行运行可执行文件时,出现了这样的错误:


OS: Windows 10

Qt: 5.14

Cmake: 3.5


enter image description here


我尝试过的:

  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} -target_link_libraries内部的静态

以上都不适合我,每当我尝试不使用Qt Creator自行运行可执行文件时,都会遇到相同的错误。


我的CMake文件:

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
        )
c++ qt build cmake static-linking
1个回答
0
投票

为什么找不到Qt5Core.dll:

© www.soinside.com 2019 - 2024. All rights reserved.