How to link CMakeLists.txt to add OpenCV 3.1 to the ros package?

asked 2017-06-29 17:26:56 -0500

Cheema gravatar image

updated 2017-06-29 23:38:18 -0500

I am trying to build autoware ros package on ubuntu 14.04.I have installed OpenCV 3.1

$ cd $HOME
$ git clone https://github.com/CPFL/Autoware.git
$ cd ~/Autoware/ros/src
$ catkin_init_workspace
$ cd ../
$ ./catkin_make_release

Upon build, it produces the following error relating OpenCV:

    CMakeFiles/imgprocx.dir/nodes/imgprocx/imgprocx.cpp.o: In function `main':
    imgprocx.cpp:(.text.startup+0x9a6): undefined reference to `cv::imread(cv::String const&, int)'
    imgprocx.cpp:(.text.startup+0x9ae): undefined reference to `cv::String::deallocate()'
    imgprocx.cpp:(.text.startup+0xaec): undefined reference to `cv::String::allocate(unsigned long)'
    imgprocx.cpp:(.text.startup+0xc08): undefined reference to `cv::String::deallocate()'
    CMakeFiles/imgprocx.dir/nodes/imgprocx/ImagePreprocessor.cpp.o: In function `ImagePreprocessor::setGamma(cv::Mat&, float, bool)':
    ImagePreprocessor.cpp:(.text+0xed6): undefined reference to `cv::LUT(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&)'
    CMakeFiles/imgprocx.dir/nodes/imgprocx/ImagePreprocessor.cpp.o: In function `ImagePreprocessor::autoAdjustGammaRGB(cv::Mat&, std::vector<cv::Mat, std::allocator<cv::Mat> >&, cv::Mat)':
    ImagePreprocessor.cpp:(.text+0x1790): undefined reference to `cv::LUT(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&)'
    collect2: error: ld returned 1 exit status
    make[2]: *** [/home/robotics/Autoware/ros/devel/lib/orb_localizer/imgprocx] Error 1
    make[1]: *** [computing/perception/localization/packages/orb_localizer/CMakeFiles/imgprocx.dir/all] Error 2
Invoking "make -j2 -l2" failed

How should I append my following CMakeLists.txt file to prevent this error? Any help will be greatly appreciated.

# toplevel CMakeLists.txt for a catkin workspace
# catkin/cmake/toplevel.cmake

cmake_minimum_required(VERSION 2.8.3)

set(CATKIN_TOPLEVEL TRUE)

# search for catkin within the workspace
set(_cmd "catkin_find_pkg" "catkin" "${CMAKE_SOURCE_DIR}")
execute_process(COMMAND ${_cmd}
  RESULT_VARIABLE _res
  OUTPUT_VARIABLE _out
  ERROR_VARIABLE _err
  OUTPUT_STRIP_TRAILING_WHITESPACE
  ERROR_STRIP_TRAILING_WHITESPACE
)
if(NOT _res EQUAL 0 AND NOT _res EQUAL 2)
  # searching fot catkin resulted in an error
  string(REPLACE ";" " " _cmd_str "${_cmd}")
  message(FATAL_ERROR "Search for 'catkin' in workspace failed (${_cmd_str}): ${_err}")
endif()

# include catkin from workspace or via find_package()
if(_res EQUAL 0)
  set(catkin_EXTRAS_DIR "${CMAKE_SOURCE_DIR}/${_out}/cmake")
  # include all.cmake without add_subdirectory to let it operate in same scope
  include(${catkin_EXTRAS_DIR}/all.cmake NO_POLICY_SCOPE)
  add_subdirectory("${_out}")

else()
  # use either CMAKE_PREFIX_PATH explicitly passed to CMake as a command line argument
  # or CMAKE_PREFIX_PATH from the environment
  if(NOT DEFINED CMAKE_PREFIX_PATH)
    if(NOT "$ENV{CMAKE_PREFIX_PATH}" STREQUAL "")
      string(REPLACE ":" ";" CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})
    endif()
  endif()

  # list of catkin workspaces
  set(catkin_search_path "")
  foreach(path ${CMAKE_PREFIX_PATH})
    if(EXISTS "${path}/.catkin")
      list(FIND catkin_search_path ${path} _index)
      if(_index EQUAL -1)
        list(APPEND catkin_search_path ${path})
      endif()
    endif()
  endforeach()

  # search for catkin in all workspaces
  set(CATKIN_TOPLEVEL_FIND_PACKAGE TRUE)
  find_package(catkin QUIET
    NO_POLICY_SCOPE
    PATHS ${catkin_search_path}
    NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
  unset(CATKIN_TOPLEVEL_FIND_PACKAGE)

  if(NOT catkin_FOUND)
    message(FATAL_ERROR "find_package(catkin) failed. catkin was neither found in the workspace nor in the CMAKE_PREFIX_PATH. One reason may be that no ROS setup.sh was sourced before.")
  endif()
endif()

catkin_workspace()
edit retag flag offensive close merge delete

Comments

# toplevel CMakeLists.txt for a catkin workspace

whatever you end up doing, don't do it in this CMakeLists.txt, as this is the top-level one (ie: the one in your src space). This doesn't (directly) build any packages.

You'll want to look at the one in the actual pkg directory.

gvdhoorn gravatar imagegvdhoorn ( 2017-06-30 02:32:21 -0500 )edit