1

I static compiled Qt5.14.0 with the MinGW compiler in windows using the following guide:

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

After compiling qt, projects created with qmake are static compiled without any errors. But projects defined as cmake give the following errors:

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();
}

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • Please take a look at an earlier response of mine on how to build a static build of qt-5.15.0 at: https://stackoverflow.com/questions/62180840/how-to-statically-compile-qt-using-mingw-compiler-and-ssl-support/62324734#62324734 – Brecht Sanders Sep 28 '20 at 05:42

1 Answers1

0

I searched for this problem a lot and found the problem in the link below, which is related to a bug in version Qt5.14.0 that has been fixed in higher versions. I tested with version Qt5.14.2 and it was compiled without error. Static linking against Qt on Windows using CMake

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