gpt4 book ai didi

c++ - 无法将 CLion 链接到 Windows 10 上的 QT

转载 作者:行者123 更新时间:2023-11-30 04:50:04 30 4
gpt4 key购买 nike

我正在尝试将 Qt Creator 链接到 Clion,这样我就可以使用它来创建 GUI 元素,但我唯一能找到的信息是这个线程

How to configure CLion IDE for Qt Framework?

我试图尽可能地遵循这一点,但主要区别之一是在 Windows 上没有 clang_64 文件,而是 msvc2017_64,这似乎是我收到的错误中显示的内容。

我的 CmakeLists.txt

cmake_minimum_required(VERSION 3.5)
project(helloqt)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

set(SOURCE_FILES main.cpp)
find_package(Qt5Widgets REQUIRED)

add_executable(helloqt ${SOURCE_FILES})

target_link_libraries(helloqt Qt5::Widgets)

我的 main.cpp

#include <QApplication>
#include <QDebug>

using namespace std;

int main() {
qDebug() << QT_VERSION_STR;
return 1;
}

在 Settings>Build, Execution, Deployment > CMake 下我的 Cmake Options 有路径

-DCMAKE_PREFIX_PATH=C:/Qt/5.12.1/msvc2017_64/lib/cmake

它导致了这个错误,我还没有找到解决办法。

"C:\Program Files\JetBrains\CLion 2018.3.4\bin\cmake\win\bin\cmake.exe" --build C:\Users\Uncorropto\CLionProjects\helloqt\cmake-build-debug --target helloqt --
Scanning dependencies of target helloqt
[ 50%] Building CXX object CMakeFiles/helloqt.dir/main.cpp.obj
main.cpp
[100%] Linking CXX executable helloqt.exe
LINK Pass 1: command "C:\PROGRA~2\MIB055~1\2017\COMMUN~1\VC\Tools\MSVC\1414~1.264\bin\Hostx86\x86\link.exe /nologo @CMakeFiles\helloqt.dir\objects1.rsp /out:helloqt.exe /implib:helloqt.lib /pdb:C:\Users\Uncorropto\CLionProjects\helloqt\cmake-build-debug\helloqt.pdb /version:0.0 /machine:X86 /debug /INCREMENTAL /subsystem:console C:\Qt\5.12.1\msvc2017_64\lib\Qt5Widgetsd.lib C:\Qt\5.12.1\msvc2017_64\lib\Qt5Guid.lib C:\Qt\5.12.1\msvc2017_64\lib\Qt5Cored.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\helloqt.dir/intermediate.manifest CMakeFiles\helloqt.dir/manifest.res" failed (exit code 1120) with the following output:
main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QMessageLogger::QMessageLogger(char const *,int,char const *)" (__imp_??0QMessageLogger@@QAE@PBDH0@Z) referenced in function _main
main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class QDebug __thiscall QMessageLogger::debug(void)const " (__imp_?debug@QMessageLogger@@QBE?AVQDebug@@XZ) referenced in function _main
main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QDebug::~QDebug(void)" (__imp_??1QDebug@@QAE@XZ) referenced in function _main
main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class QDebug & __thiscall QDebug::operator<<(char const *)" (__imp_??6QDebug@@QAEAAV0@PBD@Z) referenced in function _main
C:\Qt\5.12.1\msvc2017_64\lib\Qt5Widgetsd.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'x86'
C:\Qt\5.12.1\msvc2017_64\lib\Qt5Guid.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'x86'
C:\Qt\5.12.1\msvc2017_64\lib\Qt5Cored.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'x86'
helloqt.exe : fatal error LNK1120: 4 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files\JetBrains\CLion 2018.3.4\bin\cmake\win\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.

最佳答案

找不到像QMessageLogger 这样的符号这是 Qt Core 的一部分.请注意,您使用了引用此符号的 qDebug()!

结论很简单,将其添加到您的CMakeLists.txt:

find_package(Qt5Core REQUIRED) # this might be not needed
target_link_libraries(helloqt Qt5::Widgets Qt5::Core)

Offtopic:丢弃这个:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

因为它什么都不做。

关于c++ - 无法将 CLion 链接到 Windows 10 上的 QT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55151277/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com