[英]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.