CMake OpenCV无法指定链接库

Ada*_*ela 3 c++ linux opencv cmake

我正在尝试在Ubuntu上运行用C ++编写的OpenCV程序。我按照教程在系统上安装OpenCV。

然后,我按照教程进行操作,以使用本教程中指定的以下Cmake命令运行代码:

cmake_minimum_required(VERSION 2.8)
project( PedestrianDetection )
find_package( OpenCV REQUIRED )
add_executable( PedestrianDetection PedestrianDetection.cpp )
target_link_libraries(  ${OpenCV_LIBS} )
Run Code Online (Sandbox Code Playgroud)

但是,Cmake给了我以下输出:

    CMake Error at CMakeLists.txt:5 (target_link_libraries):
  Cannot specify link libraries for target "opencv_videostab" which is not
  built by this project.
Run Code Online (Sandbox Code Playgroud)

有人可以指出我正确的方向来链接图书馆吗?

顺便说一句,我正在使用OpenCV2.4.8

use*_*829 5

文档中

target_link_libraries:将目标链接到给定的库。

target_link_libraries(<target>[item1 [item2 [...]]] [[debug | optimized | general] <item>] ...)

指定链接给定目标时要使用的库或标志。必须使用诸如add_executable或add_library之类的命令在当前目录中创建该named。其余参数指定库名称或标志。

试一试

target_link_libraries(PedestrianDetection ${OpenCV_LIBS})
Run Code Online (Sandbox Code Playgroud)