简体   繁体   English

CMake错误:'目标不是由这个项目构建的'

[英]CMake error: 'target is not built by this project'

My CMakeLists.txt file is: 我的CMakeLists.txt文件是:

cmake_minimum_required(VERSION 3.7)
project(OpenCV_Basics)

set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES main.cpp)

find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_LIBS})
target_link_libraries(OpenCV_Basics )

add_executable(OpenCV_Basics ${SOURCE_FILES})

When I tried to compile the main.cpp, I got stucked. 当我试图编译main.cpp时,我被困了。

CMake Error at CMakeLists.txt:10 (target_link_libraries):
  Cannot specify link libraries for target "OpenCV_Basics" which is not 
built
  by this project.

What's wrong? 怎么了?

I am working in Clion on Mac. 我在Mac上的Clion工作。

add_executable defines a target, but on your code you define a target after trying to compile it. add_executable定义了一个目标,但在您的代码中,您尝试编译定义了一个目标。

just change the position of those two lines: 只需改变这两行的位置:

  • first define the target 首先定义目标

  • link the library. 链接图书馆。

like this 像这样

add_executable(OpenCV_Basics ${SOURCE_FILES})
target_link_libraries(OpenCV_Basics )

When any CMake command accepts target argument, it expects given target to be already created . 当任何CMake命令接受目标参数时,它期望已经创建了给定目标。

Correct usage: 正确用法:

# Create target 'OpenCV_Basics' 
add_executable(OpenCV_Basics ${SOURCE_FILES})
# Pass the target to other commands
target_link_libraries(OpenCV_Basics ${OpenCV_LIBRARIES})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 XCode编译器错误,使用CMake构建的项目 - XCode compiler error, with a project built using CMake 将错误与裸机目标的 cmake 项目链接起来 - linking error with cmake project for bare metal target 我用Cmake做project,生成的时候报错:Target "xxxxxxx" links to: igl::core, but the target was not found - I use Cmake to make project, but it called error when generating : Target "xxxxxxx" links to: igl::core , but the target was not found 在使用 cmake 构建的项目中添加头文件和 .cpp 文件 - Adding header and .cpp files in a project built with cmake 将柯南构建的外部解决方案添加到 cmake 项目中 - Add external solution built by conan to cmake project CMake WxWidgets 项目在 linux 上成功构建,但在 windows 上构建成功 - CMake WxWidgets project successfully built on linux but not on windows 将使用ExternalProject_Add构建的库链接到使用CMAKE_CXX_COMPILER配置的项目时出错 - Error linking library built with ExternalProject_Add to project configured with CMAKE_CXX_COMPILER cmake目标链接openssl错误 - cmake target link openssl error CMake 用户构建的库; 无法为目标指定链接库 - CMake user built libraries; cannot specify link libraries for target CMake:试图将链接库添加到未在此目录中构建的目标 - CMake: Attempted to add link library to target which is not built in this directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM