如何构建c++;CMake在MSYS2中的Qt5应用 我有一个C++ QT5“Hello World”CGIN项目; 以下是我的main.cpp和CMakeLists.txt文件: #include <QApplication> #include <QWidget> #include <QGridLayout> #include <QLabel> int main(int argc, char **argv) { QApplication app(argc, argv); QWidget widget; widget.resize(640, 480); widget.setWindowTitle("Hello, world!!!"); QGridLayout *gridLayout = new QGridLayout(&widget); QLabel * label = new QLabel("Hello, world!!!"); label->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter); gridLayout->addWidget(label); widget.show(); return app.exec(); }

如何构建c++;CMake在MSYS2中的Qt5应用 我有一个C++ QT5“Hello World”CGIN项目; 以下是我的main.cpp和CMakeLists.txt文件: #include <QApplication> #include <QWidget> #include <QGridLayout> #include <QLabel> int main(int argc, char **argv) { QApplication app(argc, argv); QWidget widget; widget.resize(640, 480); widget.setWindowTitle("Hello, world!!!"); QGridLayout *gridLayout = new QGridLayout(&widget); QLabel * label = new QLabel("Hello, world!!!"); label->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter); gridLayout->addWidget(label); widget.show(); return app.exec(); },c++,cmake,qt5,msys2,C++,Cmake,Qt5,Msys2,我只是从中复制CMakeList并写下一些非常基本的main.cpp。 然后我在我的Linux(openSUSE 15.0)上构建了它,一切正常。 现在我想在MSYS2上构建(以获得windows版本)。首先,我无法构建cmake项目,因为找不到Qt5Config.cmake文件。我补充说 set (Qt5_DIR "/mingw64/lib/cmake/Qt5") 要“手动”查找Qt5Config.cmake文件。 在将其添加到我的cmake文件后,项目已经构建得很好。 但是,当我运行mak

我只是从中复制CMakeList并写下一些非常基本的main.cpp。 然后我在我的Linux(openSUSE 15.0)上构建了它,一切正常。 现在我想在MSYS2上构建(以获得windows版本)。首先,我无法构建cmake项目,因为找不到Qt5Config.cmake文件。我补充说

set (Qt5_DIR "/mingw64/lib/cmake/Qt5")
要“手动”查找Qt5Config.cmake文件。 在将其添加到我的cmake文件后,项目已经构建得很好。 但是,当我运行
make
编译程序时,我得到以下错误:

[ 25%] Automatic MOC and UIC for target helloworld
[ 25%] Built target helloworld_autogen
[ 50%] Linking CXX executable helloworld.exe
CMakeFiles/helloworld.dir/main.cpp.o:main.cpp:(.text$_ZN15QTypedArrayDataItE10deallocateEP10QArrayData[_ZN15QTypedArrayDataItE10deallocateEP10QArrayData]+0x1c): undefined reference to `QArrayData::deallocate(QArrayData*, unsigned long, unsigned long)'
CMakeFiles/helloworld.dir/main.cpp.o:main.cpp:(.text$_ZN15QTypedArrayDataItE10deallocateEP10QArrayData[_ZN15QTypedArrayDataItE10deallocateEP10QArrayData]+0x1c): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `QArrayData::deallocate(QArrayData*, unsigned long, unsigned long)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/helloworld.dir/build.make:102: helloworld.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:73: CMakeFiles/helloworld.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
据我所知,有一些丢失的库找不到。
但是我不知道如何修复它。

您不需要CMakeLists.tx
你可以只按build按钮

你是如何安装Qt的?@DavidGrayson,
pacman-S mingw-w64-x86_64-qt5
你可以使用它,你必须使用两个命令install-dev-env和install-qt5-env,在qtcreator&Git启动后,我没有任何build按钮。我不会用同样的方法在linux和msys2上使用cmake构建我的应用程序。我仅使用vim创建qt5 gui应用程序。错了吗?你已经用过了
[ 25%] Automatic MOC and UIC for target helloworld
[ 25%] Built target helloworld_autogen
[ 50%] Linking CXX executable helloworld.exe
CMakeFiles/helloworld.dir/main.cpp.o:main.cpp:(.text$_ZN15QTypedArrayDataItE10deallocateEP10QArrayData[_ZN15QTypedArrayDataItE10deallocateEP10QArrayData]+0x1c): undefined reference to `QArrayData::deallocate(QArrayData*, unsigned long, unsigned long)'
CMakeFiles/helloworld.dir/main.cpp.o:main.cpp:(.text$_ZN15QTypedArrayDataItE10deallocateEP10QArrayData[_ZN15QTypedArrayDataItE10deallocateEP10QArrayData]+0x1c): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `QArrayData::deallocate(QArrayData*, unsigned long, unsigned long)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/helloworld.dir/build.make:102: helloworld.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:73: CMakeFiles/helloworld.dir/all] Error 2
make: *** [Makefile:84: all] Error 2