【问题标题】:Undefined references in Qt5.14.0 static using CMake (mingw) in Windows在 Windows 中使用 CMake (mingw) 在 Qt5.14.0 静态中未定义的引用
【发布时间】:2020-09-27 03:59:15
【问题描述】:

我使用以下指南在 Windows 中使用 MinGW 编译器静态编译了 Qt5.14.0:

https://amin-ahmadi.com/2017/11/01/how-to-build-qt-5-9-2-static-using-mingw/?unapproved=66401&moderation-hash=dd8787766bd2c5c39babd9aafe4255b7#comment-66401

编译qt后,使用qmake创建的项目是静态编译的,没有任何错误。但是定义为 cmake 的项目会出现以下错误:

qcoreapplication_win.cpp:-1: error: undefined reference to `GetFileVersionInfoSizeW@8'

qcoreapplication_win.cpp:-1: error: undefined reference to `GetFileVersionInfoW@16'

qcoreapplication_win.cpp:-1: error: undefined reference to `VerQueryValueW@16'

qglobal.cpp:-1: error: undefined reference to `_imp__WSACleanup@0'

qglobal.cpp:-1: error: undefined reference to `_imp__WSAStartup@8'

qglobal.cpp:-1: error: undefined reference to `_imp__WSACleanup@0'

CMakeLists.txt

cmake_minimum_required(VERSION 3.5)

project(untitled27 LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Qt5Core)

add_executable(untitled27
  main.cpp
)
target_link_libraries(untitled27 Qt5::Core)

main.cpp

#include <QCoreApplication>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    return a.exec();
}

【问题讨论】:

标签: windows qt cmake static mingw


【解决方案1】:

我搜索了很多这个问题,在下面的链接中找到了问题,这与Qt5.14.0版本中的一个错误有关,该错误已在更高版本中修复。 我用 Qt5.14.2 版本进行了测试,编译没有错误。 Static linking against Qt on Windows using CMake

https://codereview.qt-project.org/c/qt/qtbase/+/282408

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-12
    相关资源
    最近更新 更多