说实话,我不是Qt Creator的粉丝。所以我决定使用像CLion这样的另一个IDE。我研究并发现Clion不支持qmake,但是有可能让Qt-Project与cmake一起运行。
这是我的 CMakeList 。保存这个make文件时,CLion不会给我任何错误。
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)
测试它是否有效我创建了一个简单的cpp。
#include <iostream>
#include <QApplication>
using namespace std;
int main(int argc, char **argv)
{
QApplication app(argc,argv);
return app.exec();
}
我尝试按照这些说明实施它 How to configure CLion IDE for Qt Framework?
我必须使用qt提供的cmake二进制文件。所以我将Cmake选项设置为:
-DCMAKE_PREFIX_PATH=C:\Qt\Qt5.9.1\5.9.1\mingw53_32\lib\cmake
但如果我尝试编译它会给我这个错误:
"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
我下载了不同版本的Qt,因为Qt 5.9使用的是Mingw 5.3,而CLion说我使用的是Mingw 5.0,在开始时我使用的是Qt 5.6,它使用的是Mingw 4.9。我无法弄清楚它为什么不起作用。
干净的CMake Build看起来像这样
"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]
答案 0 :(得分:0)
不知何故,Qt二进制文件没有PATH。我已经添加了PATH并重建了cmake Project并且它工作正常。所以这只是路径和版本的问题。