且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CMake OpenCV不能指定链接库

更新时间:2022-10-15 08:44:48

文档


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



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



指定链接给定目标时要使用的库或标志。命名的
必须已通过
命令(如add_executable或add_library)在当前目录中创建。其余参数
指定库名称或标志。


请尝试

  target_link_libraries(PedestrianDetection $ {OpenCV_LIBS})


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

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})