我的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})
当我尝试编译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.
怎么了?
我在Mac上的Clion工作。
答案 0 :(得分:7)
add_executable定义了一个目标,但在您的代码中,您在尝试编译后定义目标。
只需更改这两行的位置:
首先定义目标
链接图书馆。
add_executable(OpenCV_Basics ${SOURCE_FILES})
target_link_libraries(OpenCV_Basics )
答案 1 :(得分:6)
当任何CMake命令接受 target 参数时,它希望给定的目标已经创建。
正确使用:
# Create target 'OpenCV_Basics'
add_executable(OpenCV_Basics ${SOURCE_FILES})
# Pass the target to other commands
target_link_libraries(OpenCV_Basics ${OpenCV_LIBRARIES})