我在我的代码中实现了CMake但是我收到了错误
"无法为目标"Qt5 :: Widgets"指定链接库,这些链接库不是由项目构建的".
以下是CMakeLists.txt的内容:
#Specify the version being used aswell as the language
cmake_minimum_required(VERSION 2.6)
#Name your project here
project(eCAD)
#Sends the -std=c++11 flag to the gcc compiler
ADD_DEFINITIONS(-std=c++11)
#This tells CMake to main.cpp and name it eCAD
add_executable(eCAD main.cpp)
#include the subdirectory containing our libs
add_subdirectory (gui)
include_directories(gui)
#include Qt directories
find_package(Qt5Widgets)
find_package(Qt5Core)
find_package(Qt5Designer)
SET(QT_USE_QTDESIGNER ON)
#link_libraries
target_link_libraries(Qt5::Widgets Qt5::Core)
Run Code Online (Sandbox Code Playgroud)
Mur*_*phy 45
除了公认的答案:一个重要的细节是放置target_link_libraries 后的add_executable 并 find_package线,因此所有连接部件都是已知的.
wRA*_*RAR 21
第一个参数target_link_libraries是目标名称:
target_link_libraries(eCAD Qt5::Widgets Qt5::Core)
Run Code Online (Sandbox Code Playgroud)
另外,不要将目标名称与项目名称混淆:
project指定项目名称,但add_executable,add_library或创建的目标add_custom_target。错误消息是关于目标的。
| 归档时间: |
|
| 查看次数: |
33581 次 |
| 最近记录: |