无法在Windows 10上将CLion链接到QT

时间:2019-03-13 21:11:27

标签: c++ windows qt user-interface cmake

我正在尝试将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;
}

在“设置”>“构建,执行,部署”下,“ CMake我的Cmake选项”具有路径

-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.

2 个答案:

答案 0 :(得分:1)

找不到QMessageLogger一部分的符号Qt Core。请注意,您曾经使用qDebug()来指代这些符号!

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

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

离题:将其丢弃:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

因为它什么都不做。

答案 1 :(得分:0)

在项目(helloqt)下尝试一下:

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)