ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Linking opencv with ROS using cmake issue

asked 2016-05-18 07:37:17 -0500

polar gravatar image

updated 2016-05-18 07:38:18 -0500

Am getting this compilation error

../devel/lib/ undefined reference to `cv::calcOpticalFlowPyrLK

In my CMake

find_package(OpenCV REQUIRED core imgproc highgui videoio  PATHS /home/polar/soft/lib/opencv/opencv-3.1.0/cmake)

... then


For info, I installled opencv 3.1.0 myself. In XY.h I just call opencv like

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include "opencv2/video/tracking.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include <opencv2/features2d.hpp>
#include "opencv2/xfeatures2d.hpp"

Any idea on the source of the problem?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2016-10-12 17:00:56 -0500

A_KN gravatar image

updated 2017-08-22 11:29:10 -0500

jayess gravatar image

Make sure you have added all run and build dependencies in your package.xml If you used catkin_create_package YOUR_PACKAGE_NAME dependecy1 dependency2 as given in , then it is automatically added in your package.xml

Otherwise add these and any other dependencies you may need:


edit flag offensive delete link more


@A_KN: I edited your answer for you but in the future please make sure to use the Preformatted Text (101010) button to make code snippets easier to read.

jayess gravatar image jayess  ( 2017-08-22 11:30:47 -0500 )edit

answered 2016-05-18 10:18:10 -0500

ROSkinect gravatar image

Try this:

find_package(catkin REQUIRED COMPONENTS     
     ${catkin_BUILD_PACKAGES} ) 
find_package(OpenCV REQUIRED)

edit flag offensive delete link more


Still undefined reference to `cv::

polar gravatar image polar  ( 2016-05-18 21:23:54 -0500 )edit

Are you sure Opencv is installed?

And for find_package you shouldn't manually hardcode your paths or copy files around, I recommend you to remove this /home/polar/soft/lib/opencv/opencv-3.1.0/cmake It will probably work but it is not the way you should do it

Did you solve the problem?

ROSkinect gravatar image ROSkinect  ( 2016-05-19 04:36:53 -0500 )edit

OpenCV is well installed on my machine. I installed both 3.1.0 and 2.4.13. I can use them outside ros but not inside. Tried this but did not help a lot Should I touch the package.xml?

polar gravatar image polar  ( 2016-06-02 06:45:32 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-05-18 07:37:17 -0500

Seen: 1,229 times

Last updated: Aug 22 '17