Ask Your Question
0

add a non-ros library c++

asked 2021-03-23 10:13:31 -0500

Spyros gravatar image

Hello. I have a C++ node working with openCV and I want to add a non-ROS library to my package. The library is here. I don't want to install the whole external package, so I just stored the slic.cpp and slic.h files in the src directory of my package. I included the libraries as is done in the demo.cpp. When I modify the CMakeLists.txt of my package as I found in several tutorials, and I compile with catkin_make I get these errors:

/home/spyros/catkin_ws/src/door_detector_1/src/slic.cpp:682:6: error: ‘_ASSERT’ was not declared in this scope
      _ASSERT( y < m_height && x < m_width && y >= 0 && x >= 0 );
      ^~~~~~~
/home/spyros/catkin_ws/src/door_detector_1/src/slic.cpp:682:6: note: suggested alternative: ‘CV_ASSERT’
      _ASSERT( y < m_height && x < m_width && y >= 0 && x >= 0 );
      ^~~~~~~
      CV_ASSERT
/home/spyros/catkin_ws/src/door_detector_1/src/slic.cpp:734:4: error: ‘_ASSERT’ was not declared in this scope
    _ASSERT(klabels[j] >= 0);
    ^~~~~~~
/home/spyros/catkin_ws/src/door_detector_1/src/slic.cpp:734:4: note: suggested alternative: ‘CV_ASSERT’
    _ASSERT(klabels[j] >= 0);
    ^~~~~~~
    CV_ASSERT
/home/spyros/catkin_ws/src/door_detector_1/src/slic.cpp: In member function ‘void SLIC::SaveSuperpixelLabels(const int*, const int&, const int&, const string&, const string&)’:
/home/spyros/catkin_ws/src/door_detector_1/src/slic.cpp:776:13: error: ‘_MAX_FNAME’ was not declared in this scope
  char fname[_MAX_FNAME];
             ^~~~~~~~~~
/home/spyros/catkin_ws/src/door_detector_1/src/slic.cpp:776:13: note: suggested alternative: ‘__ASMNAME’
  char fname[_MAX_FNAME];
             ^~~~~~~~~~
             __ASMNAME
/home/spyros/catkin_ws/src/door_detector_1/src/slic.cpp:778:43: error: ‘fname’ was not declared in this scope
  _splitpath(filename.c_str(), NULL, NULL, fname, extn);
                                           ^~~~~
/home/spyros/catkin_ws/src/door_detector_1/src/slic.cpp:778:43: note: suggested alternative: ‘rename’
  _splitpath(filename.c_str(), NULL, NULL, fname, extn);
                                           ^~~~~
                                           rename
/home/spyros/catkin_ws/src/door_detector_1/src/slic.cpp:778:50: error: ‘extn’ was not declared in this scope
  _splitpath(filename.c_str(), NULL, NULL, fname, extn);
                                                  ^~~~
/home/spyros/catkin_ws/src/door_detector_1/src/slic.cpp:778:50: note: suggested alternative: ‘exit’
  _splitpath(filename.c_str(), NULL, NULL, fname, extn);
                                                  ^~~~
                                                  exit
/home/spyros/catkin_ws/src/door_detector_1/src/slic.cpp:778:2: error: ‘_splitpath’ was not declared in this scope
  _splitpath(filename.c_str(), NULL, NULL, fname, extn);
  ^~~~~~~~~~
/home/spyros/catkin_ws/src/door_detector_1/src/slic.cpp:778:2: note: suggested alternative: ‘realpath’
  _splitpath(filename.c_str(), NULL, NULL, fname, extn);
  ^~~~~~~~~~
  realpath

I think I'm doing something wrong in my CMakeLists.txt:

cmake_minimum_required(VERSION 3.0.2)
project(door_detector_1)

add_compile_options(-std=c++11)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
  message_generation
  cv_bridge
)

find_package(GTSAM REQUIRED)
find_package(OpenCV 3.2.0 REQUIRED)

SET(BUILD_SHARED_LIBS on)

catkin_package(
  INCLUDE_DIRS include
  LIBRARIES slic
  CATKIN_DEPENDS roscpp rospy std_msgs message_runtime cv_bridge image_transport
#  DEPENDS slic
)

include_directories(${GTSAM_INCLUDE_DIR} ${catkin_INCLUDE_DIRS} src)
include_directories(${OpenCV_INCLUDE_DIRS})

add_library(slic src/slic.cpp)

target_link_libraries(slic ${OpenCV_LIBRARIES})

add_executable(vision_trials src/vision_trials.cpp)
target_link_libraries(vision_trials gtsam ${catkin_LIBRARIES})
target_link_libraries(vision_trials ${OpenCV_LIBRARIES})
add_dependencies(vision_trials door_detector_1_generate_messages_cpp)
target_link_libraries(vision_trials slic)

What am I doing wrong here? I'm confused with the different ... (more)

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
3

answered 2021-03-23 10:35:19 -0500

jpace121 gravatar image

_splitPath and _ASSERT are Win32 functions that don’t exist on Linux. You’ll need to modify the source code you’re compiling to use the Linux equivalents.

edit flag offensive delete link more

Comments

I found another code sample that compiles with no errors. Thanks. Is there any step by step guide for CMakeLists.txt modifications in different cases? (Use a non ros library, use a library from a different package etc)

Spyros gravatar image Spyros  ( 2021-03-25 02:20:26 -0500 )edit

Not that I know of. This is probably the closest.

jpace121 gravatar image jpace121  ( 2021-03-28 12:12:08 -0500 )edit
0

answered 2021-03-23 21:48:46 -0500

danambrosio gravatar image

If you use CMake version 3.11 or greater (specified in your CMakeList.txt cmake_minimum_required_version) you can use the FetchContent module to include the SLIC-superpixel-with-OpenCV library in your package. See documentation on FetchContent for an example.

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: 2021-03-23 10:13:31 -0500

Seen: 118 times

Last updated: Mar 23 '21