提问人:Antonio Santoro 提问时间:7/17/2019 最后编辑:Antonio Santoro 更新时间:7/17/2019 访问量:1005
构建简单的 QT 项目时未定义引用
Undefined referenced when building a simple QT project
问:
我无法使用 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 编译的
答: 暂无答案
评论
0xC0000135
.pro
qmake -project
.ui
set(CMAKE_AUTOUIC ON)
CMake
ui_
moc_
cmake-build