我正在尝试使用QT库编译一个简单的程序。问题是我无法弄清楚如何将这些库与CLion一起使用。这是我的CMakeLists.txt文件:
cmake_minimum_required(VERSION 3.3)
project(qt_1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
find_package( Qt5Core REQUIRED )
find_package( Qt5Widgets REQUIRED )
find_package( Qt5Gui REQUIRED )
add_executable(qt_1 ${SOURCE_FILES})
qt5_use_modules(qt_1 Core Widgets Gui)
我是从this post获取的。我也尝试了各种来源的多个例子,但我得到了同样的错误。
我编译时得到的错误是:
"C:\Program Files (x86)\JetBrains\CLion 1.2.4\bin\cmake\bin\cmake.exe" --build C:\Users\Andrei\.CLion12\system\cmake\generated\5ef88d9c\5ef88d9c\Debug -- target qt_1 -- -j 8
CMake Error at CMakeLists.txt:8 (find_package):
-- Configuring incomplete, errors occurred!
By not providing "FindQt5Core.cmake" in CMAKE_MODULE_PATH this project has
See also "C:/Users/Andrei/.CLion12/system/cmake/generated/5ef88d9c/5ef88d9c/Debug/CMakeFiles/CMakeOutput.log".
asked CMake to find a package configuration file provided by "Qt5Core", but
CMake did not find one.
Could not find a package configuration file provided by "Qt5Core" with any
of the following names:
Qt5CoreConfig.cmake
qt5core-config.cmake
Add the installation prefix of "Qt5Core" to CMAKE_PREFIX_PATH or set
"Qt5Core_DIR" to a directory containing one of the above files. If
"Qt5Core" provides a separate development package or SDK, be sure it has
been installed.
mingw32-make.exe: *** [cmake_check_build_system] Error 1
Makefile:175: recipe for target 'cmake_check_build_system' failed
我正在运行windws 8.1,我已将QT bin文件夹添加到路径。
UPDATE1: CMakeLists.txt现在工作正常,我可以包括QT库没有问题。但是现在我在编译时得到了这个东西:
undefined reference to `_imp___ZN12QApplicationC1ERiPPci'
这是我当前的CMakeLists.txt文件:
cmake_minimum_required(VERSION 3.3)
project(qt_1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_PREFIX_PATH C:/Qt/5.6/msvc2015_64)
set(SOURCE_FILES main.cpp)
find_package( Qt5Core REQUIRED )
find_package( Qt5Widgets REQUIRED )
find_package( Qt5Gui REQUIRED )
add_executable(qt_1 ${SOURCE_FILES})
qt5_use_modules(qt_1 Core Widgets Gui)