构建简单的 QT 项目时未定义引用

Undefined referenced when building a simple QT project

提问人:Antonio Santoro 提问时间:7/17/2019 最后编辑:Antonio Santoro 更新时间:7/17/2019 访问量:1005

问:

我无法使用 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 编译的

C++ Qt mingw 未定义引用

评论

0赞 Kuba hasn't forgotten Monica 7/17/2019
所以,你现在要建造它了吗?我建议使用Qt Creator,它支持qmake,而Qt附带了mingw支持,因此使用Qt Creator可以很容易地完成所有这些操作。您的问题可能来自使用 clion。
0赞 drescherjm 7/17/2019
你有没有用谷歌搜索过0xC0000135
0赞 Antonio Santoro 7/18/2019
因此,我首先必须做两件事,首先为MinGW设置正确的路径,然后使用.现在我已使用 Designer 创建,如何自动将头文件添加到我的项目文件夹中?在我放入的 CMake 中,但在我构建时它不会生成任何头文件.proqmake -project.uiset(CMAKE_AUTOUIC ON)
0赞 drescherjm 7/18/2019
在首选模式下(指定与源不同的生成文件夹)在生成文件夹中生成,该文件夹应与源文件夹不同。CMake
0赞 Antonio Santoro 7/18/2019
@drescherjm有没有办法将 CMake 设置为将 and 文件保存到源目录而不是目录中?ui_moc_cmake-build

答: 暂无答案