Windows 中使用 CMake (mingw) 静态 Qt5.14.0 中的未定义引用

Undefined references in Qt5.14.0 static using CMake (mingw) in Windows

我使用以下指南在 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();
}

这个问题我搜索了很多,发现问题在下面的link,与Qt5.14.0版本的一个bug有关,高版本已经修复。 我用Qt5.14.2版本测试,编译没有报错。

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