Ask Your Question
0

opencv in makefile

asked 2013-10-06 23:09:18 -0500

nickstu gravatar image

updated 2013-10-06 23:12:26 -0500

I seem to have a very basic problem, and yet I can't figure it out. I am trying to load a simple image and show it with opencv, but i keep on getting undefined references

nickstu@nickstu-asus:~/catkin_ws$ catkin_make
Base path: /home/nickstu/catkin_ws
Source space: /home/nickstu/catkin_ws/src
Build space: /home/nickstu/catkin_ws/build
Devel space: /home/nickstu/catkin_ws/devel
Install space: /home/nickstu/catkin_ws/install
####
#### Running command: "make cmake_check_build_system" in "/home/nickstu/catkin_ws/build"
####
-- Using CATKIN_DEVEL_PREFIX: /home/nickstu/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/groovy
-- This workspace overlays: /opt/ros/groovy
-- Using Debian Python package layout
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/nickstu/catkin_ws/build/test_results
-- Found gtest sources under '/usr/src/gtest': gtests will be built
-- catkin 0.5.71
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 1 packages in topological order:
-- ~~  - beginner_tutorials
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'beginner_tutorials'
-- ==> add_subdirectory(beginner_tutorials)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/nickstu/catkin_ws/build
####
#### Running command: "make -j4 -l4" in "/home/nickstu/catkin_ws/build"
####
Linking CXX executable /home/nickstu/catkin_ws/devel/lib/beginner_tutorials/listener
[ 50%] Built target talker
CMakeFiles/listener.dir/src/listener.cpp.o: In function `cameraROSCallback(boost::shared_ptr<sensor_msgs::Image_<std::allocator<void> > const> const&)':
listener.cpp:(.text+0x63): undefined reference to `cv::imread(std::string const&, int)'
listener.cpp:(.text+0x103): undefined reference to `cv::namedWindow(std::string const&, int)'
listener.cpp:(.text+0x134): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
listener.cpp:(.text+0x174): undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
listener.cpp:(.text+0x19c): undefined reference to `cv::waitKey(int)'
CMakeFiles/listener.dir/src/listener.cpp.o: In function `cv::Mat::~Mat()':
listener.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
CMakeFiles/listener.dir/src/listener.cpp.o: In function `cv::Mat::operator=(cv::Mat const&)':
listener.cpp:(.text._ZN2cv3MataSERKS0_[_ZN2cv3MataSERKS0_]+0x111): undefined reference to `cv::Mat::copySize(cv::Mat const&)'
CMakeFiles/listener.dir/src/listener.cpp.o: In function `cv::Mat::release()':
listener.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x47): undefined reference to `cv::Mat::deallocate()'
collect2: error: ld returned 1 exit status
make[2]: *** [/home/nickstu/catkin_ws/devel/lib/beginner_tutorials/listener] Error 1
make[1]: *** [beginner_tutorials/CMakeFiles/listener.dir/all] Error 2
make: *** [all] Error 2
Invoking "make" failed

This is my CMakeLists, i understand that I am missing something in here but I can't find out what it is.

cmake_minimum_required(VERSION 2.8.3)
project(beginner_tutorials)
find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs)
find_package( OpenCV REQUIRED )
include_directories(
  ${catkin_INCLUDE_DIRS}
)

include_directories(include ${catkin_INCLUDE_DIRS})
include_directories(SYSTEM ${OpenCV_INCLUDE_DIRS})

add_executable(talker src/talker.cpp)
target_link_libraries(talker ${catkin_LIBRARIES})

add_executable(listener src/listener.cpp)
target_link_libraries(listener ${catkin_LIBRARIES})

and this is the actual code

#include <ros/ros.h>
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <sensor_msgs/Image.h>

using namespace std;
using namespace cv;

void cameraROSCallback(const sensor_msgs::Image::ConstPtr& msg){

    Mat image;
    image = imread("file.bmp", CV_LOAD_IMAGE_COLOR);
    if(! image.data )
            {
            cout <<  "Could not open or find the image" << std::endl ;
            }

        namedWindow( "Display ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2013-10-07 00:36:41 -0500

JonW gravatar image

Looks like it is failing to find the libraries when linking. Examination of the wiki entry for the vision_opencv package shows that you also need to add the variable "${OpenCV_LIBRARIES}" to the target_link_libraries entry.

A little experimentation seems to show that changing your link command to the following fixes your problem:

target_link_libraries(listener ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})

edit flag offensive delete link more

Comments

thanks, that solved it!

nickstu gravatar imagenickstu ( 2013-10-07 03:47: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

Stats

Asked: 2013-10-06 23:09:18 -0500

Seen: 4,797 times

Last updated: Oct 07 '13