0

To be honest im not a fan of Qt Creator. So I decided to use another IDE like CLion. I researched and found out that Clion doesnt support qmake, but it is possible to get a Qt-Project to run with cmake.

Thats my CMakeList. CLion don't give me any error when i save this make-file.

cmake_minimum_required(VERSION 3.8)
project(Qt_CmakeTest)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
add_executable(Qt_CmakeTest ${SOURCE_FILES})
target_link_libraries(Qt_CmakeTest Qt5::Core Qt5::Widgets)

to test if it worked I created a simple cpp.

#include <iostream>
#include <QApplication>

using namespace std;
int main(int argc, char **argv)
{
    QApplication app(argc,argv);
    return app.exec();
}

I tried to implement it following these instructions How to configure CLion IDE for Qt Framework?

I have to use the cmake binary that qt provides. So I set the Cmake Option to:

-DCMAKE_PREFIX_PATH=C:\Qt\Qt5.9.1\5.9.1\mingw53_32\lib\cmake

But if I try to compile it it gives me this error:

"C:\Program Files\JetBrains\CLion 2017.2.2\bin\cmake\bin\cmake.exe" --build 
C:\Users\Marcel\Desktop\Projekte\Qt\Qt-CmakeTest\cmake-build-debug --target Qt_CmakeTest -- -j 2
[ 50%] Linking CXX executable Qt_CmakeTest.exe
CMakeFiles\Qt_CmakeTest.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/Marcel/Desktop/Projekte/Qt/Qt-CmakeTest/main.cpp:7: undefined reference to `_imp___ZN12QApplicationC1ERiPPci'
C:/Users/Marcel/Desktop/Projekte/Qt/Qt-CmakeTest/main.cpp:8: undefined reference to `_imp___ZN12QApplication4execEv'
C:/Users/Marcel/Desktop/Projekte/Qt/Qt-CmakeTest/main.cpp:7: undefined reference to `_imp___ZN12QApplicationD1Ev'
C:/Users/Marcel/Desktop/Projekte/Qt/Qt-CmakeTest/main.cpp:7: undefined reference to `_imp___ZN12QApplicationD1Ev'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [Qt_CmakeTest.exe] Error 1
CMakeFiles\Qt_CmakeTest.dir\build.make:99: recipe for target 'Qt_CmakeTest.exe' failed
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/Qt_CmakeTest.dir/all' failed
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/Qt_CmakeTest.dir/rule' failed
Makefile:117: recipe for target 'Qt_CmakeTest' failed
mingw32-make.exe[2]: *** [CMakeFiles/Qt_CmakeTest.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/Qt_CmakeTest.dir/rule] Error 2
mingw32-make.exe: *** [Qt_CmakeTest] Error 2

I downloaded different versions of Qt because Qt 5.9 uses Mingw 5.3 and CLion says I'm using Mingw 5.0 and at the beginning I used Qt 5.6 and it used Mingw 4.9. I can't really figure out why it is not working.

A clean CMake Build looks like this

"C:\Program Files\JetBrains\CLion 2017.2.2\bin\cmake\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\Marcel\Desktop\Projekte\Qt\Qt-CmakeTest
-- The C compiler identification is GNU 6.3.0
-- The CXX compiler identification is GNU 6.3.0
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/Marcel/Desktop/Projekte/Qt/Qt-CmakeTest/cmake-build-debug

[Finished]
MNCODE
  • 159
  • 3
  • 16
  • You linked to `Qt5::Widgets` but you seem to also need to link to `Qt5::Core`. – nwp Oct 05 '17 at 13:25
  • updated the CMakeList. Still not working. Also tried to set the path with set(CMAKE_PREFIX_PATH "C:/Qt/Qt5.9.1/5.9.1/msvc2017_64") and tried different versions.(VS, mingw) – MNCODE Oct 05 '17 at 13:29
  • Did the error message change at all? Did you try to find out what other libraries Qt has that may be required? – nwp Oct 05 '17 at 13:30
  • No it did not changed. I don't know, but in the post i have linked they said you dont need more libraries – MNCODE Oct 05 '17 at 13:33
  • Are you sure you rebuilt the project properly and not just seeing the product of an old makefile? – nwp Oct 05 '17 at 13:35
  • yes I'm also restarting the IDE and realoading the CMake project – MNCODE Oct 05 '17 at 13:39
  • Restarting the IDE and the project doesn't do anything. Cmake has a build folder where it caches the makefile. In theory you can somehow tell it to rebuild your application. In practice deleting the build folder is easier. – nwp Oct 05 '17 at 13:41
  • okay deleted the whole cmake-build-debug folder and rebuild the project, but it gives still the exact same error – MNCODE Oct 05 '17 at 13:49
  • I'm using CMake with Qt, but I'm using an older syntax. Looking at the CMake 3.8 syntax, your `find_package()` looks different than [their example](https://cmake.org/cmake/help/v3.8/manual/cmake-qt.7.html). Can you post the complete output of a clean CMake generation and build? – metal Oct 05 '17 at 13:50
  • There doesn't seem to be an error in your clean cmake build. – nwp Oct 05 '17 at 13:59
  • Sry I thought i had to add an cmake build without an error ? what does clean cmake generation an build mean ? – MNCODE Oct 05 '17 at 14:06
  • 1
    I think @metal meant a clean build of your actual code that produces an error. The output with the error you are showing above skips the compilation phase because the code was compiled already. So you would delete your build directory again, build it again and show the output of that clean build (with no previous files already compiled). – nwp Oct 05 '17 at 14:10

1 Answers1

0

Somehow there was no PATH to the Qt binary. I have added the PATH and rebuild the cmake Project and it worked. So it was just a matter of the path and of the versions.

MNCODE
  • 159
  • 3
  • 16