Im trying to link Qt Creator to Clion so i can use it for creating GUI elements but the only information I was able to find on doing this was this thread
How to configure CLion IDE for Qt Framework?
I tried to follow this as closely as possible but one of the major differences is that on windows there is no clang_64 file instead it is msvc2017_64 and that is what seems to be showing up in the error im getting.
My 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)
my main.cpp
#include <QApplication>
#include <QDebug>
using namespace std;
int main() {
qDebug() << QT_VERSION_STR;
return 1;
}
under Settings>Build, Execution, Deployment > CMake my Cmake Options has the path
-DCMAKE_PREFIX_PATH=C:/Qt/5.12.1/msvc2017_64/lib/cmake
and it results in this error which I have not been able to find a fix to.
"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.
It can't find symbol like QMessageLogger which is part of Qt Core. Note you have used qDebug()
which refers to this symbols!
Conclusion is simple add this to your CMakeLists.txt
:
find_package(Qt5Core REQUIRED) # this might be not needed
target_link_libraries(helloqt Qt5::Widgets Qt5::Core)
Offtopic: trash this:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
since it doesn't do anything.
Try this under project(helloqt):
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
User contributions licensed under CC BY-SA 3.0