Ask Your Question
0

undefined reference to symbol 'cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'

asked 2015-03-31 08:31:30 -0600

vincentweisen gravatar image

I am trying to convert RGB image to Grayscale in ROS, but I am getting the error as below:

/usr/bin/ld: CMakeFiles/color_to_gray_node.dir/src/color_to_gray.cpp.o: undefined reference to symbol 'cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
/usr/bin/ld: note: 'cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)' is defined in DSO /opt/ros/groovy/lib/libopencv_imgproc.so.2.4 so try adding it to the linker command line
/opt/ros/groovy/lib/libopencv_imgproc.so.2.4: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
make[2]: *** [/home/vincentee/catkin_ws/devel/lib/get_image/color_to_gray_node] Error 1
make[1]: *** [get_image/CMakeFiles/color_to_gray_node.dir/all] Error 2
make: *** [all] Error 2

below is my CMakelist:

cmake_minimum_required(VERSION 2.8.3)
project(get_image)

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
sensor_msgs
cv_bridge
roscpp
std_msgs
image_transport
)

## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)


## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()

################################################
## Declare ROS messages, services and actions ##
################################################

## To declare and build messages, services or actions from within this
## package, follow these steps:
## * Let MSG_DEP_SET be the set of packages whose message types you use in
##   your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
## * In the file package.xml:
##   * add a build_depend and a run_depend tag for each package in MSG_DEP_SET
##   * If MSG_DEP_SET isn't empty the following dependencies might have been
##     pulled in transitively but can be declared for certainty nonetheless:
##     * add a build_depend tag for "message_generation"
##     * add a run_depend tag for "message_runtime"
## * In this file (CMakeLists.txt):
##   * add "message_generation" and every package in MSG_DEP_SET to
##     find_package(catkin REQUIRED COMPONENTS ...)
##   * add "message_runtime" and every package in MSG_DEP_SET to
##     catkin_package(CATKIN_DEPENDS ...)
##   * uncomment the add_*_files sections below as needed
##     and list every .msg/.srv/.action file to be processed
##   * uncomment the generate_messages entry below
##   * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)

## Generate messages in the 'msg' folder
# add_message_files(
#   FILES
#   Message1.msg
#   Message2.msg
# )

## Generate services in the 'srv' folder
# add_service_files(
#   FILES
#   Service1.srv
#   Service2.srv
# )

## Generate actions in the 'action' folder
# add_action_files(
#   FILES
#   Action1.action
#   Action2.action
# )

## Generate added messages and services with any dependencies listed here
# generate_messages(
#   DEPENDENCIES
#   std_msgs  # Or other packages containing msgs
# )

###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if you package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES get_image
#  CATKIN_DEPENDS other_catkin_pkg
#  DEPENDS system_lib
)

###########
## Build ##
###########

## Specify additional locations of header files
## Your package locations should be listed before other locations
 include_directories(${catkin_INCLUDE_DIRS})

## Declare a ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2015-05-04 09:00:34 -0600

timster gravatar image

updated 2015-05-04 11:16:52 -0600

Wolf gravatar image

It seems to me that you don't link to OpenCV. Do this by adding the following line to your CMakeLists.txt

find_package(OpenCV REQUIRED)

And you might also need to link your executable/library to it

target_link_libraries(your_target ${OpenCV_LIBS})

In your case change

 target_link_libraries(color_to_gray_node ${catkin_LIBRARIES})

for

 target_link_libraries(color_to_gray_node ${catkin_LIBRARIES} ${OpenCV_LIBS} )
edit flag offensive delete link more

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: 2015-03-31 08:31:30 -0600

Seen: 3,381 times

Last updated: May 04 '15