CMake OpenCV Cannot Specify Link Libraries

2019-05-10 19:56发布

I am trying to run an OpenCV program written in C++ on Ubuntu. I followed this tutorial to install OpenCV on my system.

I then followed this tutorial to run my code with the following Cmake commands as specified in the tutorial:

cmake_minimum_required(VERSION 2.8)
project( PedestrianDetection )
find_package( OpenCV REQUIRED )
add_executable( PedestrianDetection PedestrianDetection.cpp )
target_link_libraries(  ${OpenCV_LIBS} )

However, Cmake gives me the following output:

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

Can someone point me in the right direction to link the libraries?

By the way, I am using OpenCV2.4.8

1条回答
Melony?
2楼-- · 2019-05-10 20:32

from the documentation

target_link_libraries: Link a target to given libraries.

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

Specify libraries or flags to use when linking a given target. The named must have been created in the current directory by a command such as add_executable or add_library. The remaining arguments specify library names or flags.

try instead

target_link_libraries(PedestrianDetection ${OpenCV_LIBS})
查看更多
登录 后发表回答