我无法使用CLion编译简单的main.cpp
文件
#include <QWidget>
#include <QApplication>
#include <QPushButton>
#include <QDebug>
#include <QLabel>
int main(int argc, char** argv) {
QApplication application(argc, argv);
QLabel *label = new QLabel("Hello QT!");
label->show();
int res = application.exec();
delete label;
return res;
}
这是输出
====================[ Build | Lab5_autogen | Debug ]============================
C:\Users\user\.CLion2019.1\system\cygwin_cmake\bin\cmake.exe --build "/cygdrive/d/user/workspace/CLionProjects/PDS_Cpp/Laboratorio 5/cmake-build-debug" --target Lab5_autogen -- -j 2
[100%] Automatic MOC and UIC for target Lab5
[100%] Built target Lab5_autogen
Build finished
====================[ Build | Lab5 | Debug ]====================================
C:\Users\user\.CLion2019.1\system\cygwin_cmake\bin\cmake.exe --build "/cygdrive/d/user/workspace/CLionProjects/PDS_Cpp/Laboratorio 5/cmake-build-debug" --target Lab5 -- -j 2
[ 25%] Automatic MOC and UIC for target Lab5
[ 25%] Built target Lab5_autogen
[ 50%] Linking CXX executable Lab5.exe
CMakeFiles/Lab5.dir/main.cpp.o: In function `QTypedArrayData<unsigned short>::deallocate(QArrayData*)':
C:/Qt/5.12.3/mingw73_64/include/QtCore/qarraydata.h:239: undefined reference to `QArrayData::deallocate(QArrayData*, unsigned long, unsigned long)'
C:/Qt/5.12.3/mingw73_64/include/QtCore/qarraydata.h:239:(.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[3]: *** [CMakeFiles/Lab5.dir/build.make:103: Lab5.exe] Error 1
make[2]: *** [CMakeFiles/Makefile2:73: CMakeFiles/Lab5.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/Lab5.dir/rule] Error 2
make: *** [Makefile:118: Lab5] Error 2
CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
project(Lab5)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Charts REQUIRED)
list(APPEND LIBRARIES
Qt5::Core
Qt5::Gui
Qt5::Widgets
Qt5::Charts)
list(REMOVE_DUPLICATES LIBRARIES)
add_executable(Lab5 "main.cpp")
target_link_libraries(Lab5 ${LIBRARIES})
我已经添加了这一行
-DCMAKE_PREFIX_PATH=C:\Qt\5.12.3\mingw73_64\lib\cmake
在File -> Settings -> Build, Execution, Deployment -> CMake -> CMake options
我非常确定我不需要.pro
文件,我的老师能够在没有该文件的情况下编译该项目。
更新
我使用以下方法将MinGW设置为默认编译器
C:\Qt\Tools\mingw730_64
但是没有创建窗口,我得到了这个输出
"D:\user\workspace\CLionProjects\PDS_Cpp\Laboratorio 5\cmake-build-debug\Lab5.exe"
Process finished with exit code -1073741515 (0xC0000135)
以前我是使用cygwin编译的