Open jagannatharjun opened 5 years ago
hmm i seem to remember running into the same. From what i remember, i found out that the static qt builds only seems to accept static libraries. Not sure what goes wrong there, but i suspect its something related to the autostatic setting patched into cmake, since i only ran into it when the project used cmake.
I am also unable to build anything linking to qt5-static. It used to work in the past (around Qt 5.10 version).
Reproduction steps:
CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
project(static_qt)
set(CMAKE_PREFIX_PATH "C:/msys64/mingw32/qt5-static")
find_package(Qt5 5 REQUIRED Core)
add_executable(static_qt main.cpp)
target_link_libraries(static_qt PUBLIC Qt5::Core)
main.cpp
#include <QObject>
int main()
{
QObject object;
return 0;
}
Result:
====================[ Build | static_qt | Debug-mingw32 ]=======================
"C:\Program Files\JetBrains\CLion-2018.3.4\bin\cmake\win\bin\cmake.exe" --build C:\static-qt\cmake-build-debug-mingw32 --target static_qt -- -j 4
Scanning dependencies of target static_qt
[ 50%] Building CXX object CMakeFiles/static_qt.dir/main.cpp.obj
[100%] Linking CXX executable static_qt.exe
CMakeFiles\static_qt.dir/objects.a(main.cpp.obj): In function `main':
C:/static-qt/main.cpp:5: undefined reference to `QObject::QObject(QObject*)'
C:/static-qt/main.cpp:5: undefined reference to `QObject::~QObject()'
collect2.exe: error: ld returned 1 exit status
mingw32-make[3]: *** [CMakeFiles\static_qt.dir\build.make:89: static_qt.exe] Error 1
mingw32-make[2]: *** [CMakeFiles\Makefile2:72: CMakeFiles/static_qt.dir/all] Error 2
mingw32-make[1]: *** [CMakeFiles\Makefile2:84: CMakeFiles/static_qt.dir/rule] Error 2
mingw32-make: *** [Makefile:117: static_qt] Error 2
use vcpkg
I have the same annoying problem which I haven't solved yet:
E:\Qt_Creator\Tools\CMake_64\bin\cmake.exe --build G:\DB_Connector\CLion\db_connector\cmake-build-debug --target db_connector -- -j 9
[ 25%] Built target gtest
[ 50%] Built target gtest_main
[ 62%] Automatic MOC and UIC for target db_connector
[ 62%] Built target db_connector_autogen
[ 75%] Linking CXX executable db_connector.exe
CMakeFiles\db_connector.dir/objects.a(main.cpp.obj): In function `main':
G:/DB_Connector/CLion/db_connector/src/main.cpp:5: undefined reference to `__imp__ZN12QApplicationC1ERiPPci'
G:/DB_Connector/CLion/db_connector/src/main.cpp:6: undefined reference to `__imp__ZN11QPushButtonC1ERK7QStringP7QWidget'
G:/DB_Connector/CLion/db_connector/src/main.cpp:8: undefined reference to `__imp__ZN7QWidget4showEv'
G:/DB_Connector/CLion/db_connector/src/main.cpp:9: undefined reference to `__imp__ZN12QApplication4execEv'
G:/DB_Connector/CLion/db_connector/src/main.cpp:6: undefined reference to `__imp__ZN11QPushButtonD1Ev'
G:/DB_Connector/CLion/db_connector/src/main.cpp:5: undefined reference to `__imp__ZN12QApplicationD1Ev'
G:/DB_Connector/CLion/db_connector/src/main.cpp:6: undefined reference to `__imp__ZN11QPushButtonD1Ev'
G:/DB_Connector/CLion/db_connector/src/main.cpp:5: undefined reference to `__imp__ZN12QApplicationD1Ev'
CMakeFiles\db_connector.dir/objects.a(main.cpp.obj): In function `QString::QString(char const*)':
E:/Qt_Creator/5.15.0/msvc2019_64/include/QtCore/qstring.h:831: undefined reference to `__imp__ZN7QString16fromAscii_helperEPKci'
CMakeFiles\db_connector.dir/objects.a(main.cpp.obj): In function `QWidget::resize(int, int)':
E:/Qt_Creator/5.15.0/msvc2019_64/include/QtWidgets/qwidget.h:854: undefined reference to `__imp__ZN7QWidget6resizeERK5QSize'
CMakeFiles\db_connector.dir/objects.a(main.cpp.obj): In function `QTypedArrayData<unsigned short>::deallocate(QArrayData*)':
E:/Qt_Creator/5.15.0/msvc2019_64/include/QtCore/qarraydata.h:239: undefined reference to `__imp__ZN10QArrayData10deallocateEPS_yy'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [src\CMakeFiles\db_connector.dir\build.make:134: src/db_connector.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:226: src/CMakeFiles/db_connector.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:233: src/CMakeFiles/db_connector.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:195: db_connector] Error 2
I know this one, because I've just run into it: the compiler has found the non static include files. On Windows these contain magic necessary to force linkage to a DLL. You'll need to use the specific pkg-config setup provided by qt-static.
when compiling a cmake project using Modules `Quick Core Qml QuickWidgets, the static compile fails with the following linker errors
cmake command line is as follows:
cmake ../ -G Ninja "-DCMAKE_CXX_COMPILER:STRING=E:/Cpp/msys2/mingw64/bin/g++.exe" "-DCMAKE_C_COMPILER:STRING=E:/Cpp/msys2/mingw64/bin/gcc.exe" "-DCMAKE_PREFIX_PATH:STRING=E:/Cpp/msys2/mingw64/qt5-static" "-DQT_QMAKE_EXECUTABLE:STRING=E:/Cpp/msys2/mingw64/qt5-static/bin/qmake.exe"
Though qmake-static, qmake-dynamic and cmake dynamic builds works as expected