cmake - 遇到CMake错误:无法为非项目创建的目标指定链接库

标签 cmake

我在代码中实现CMake,但出现错误

"Cannot specify link libraries for target "Qt5::Widgets" which is not built by the project".



以下是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) 

最佳答案

target_link_libraries的第一个参数是目标名称:

target_link_libraries(eCAD Qt5::Widgets Qt5::Core) 

关于cmake - 遇到CMake错误:无法为非项目创建的目标指定链接库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61648036/

相关文章:

c++ - CMake在msys2下找不到静态wxWidgets

cmake - CMake CMakeLists 文件中的 "CACHE STRING"是什么意思?

c++ - X11 未正确链接 CMAKE -> 命令行中缺少 DSO

file - 在CMake中,如何找到包含文件的目录?

android - 将符号上传到 Firebase Crashlytics 时出错

使用 contribute_world 编译 opencv_world 时 opencv3.2 build on vs2017 报错

c++ - 如何使用 CMake?

c++ - 交叉编译时如何处理依赖关系

c++ - 无法确定项目的链接语言

visual-studio - 在 CMake 中设置 MSVC 运行时