0
$\begingroup$

Rosanswers logo

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 modifications needed in CMakeLists.txt in different cases (adding non-ROS library, adding a library used in a different package etc).

I use ubuntu 18.04, C++11 and ROS melodic.

Any feedback is appreciated. Thanks in advance.


Originally posted by Spyros on ROS Answers with karma: 51 on 2021-03-23

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

_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.


Originally posted by jpace121 with karma: 56 on 2021-03-23

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by Spyros on 2021-03-25:
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)

Comment by jpace121 on 2021-03-28:
Not that I know of. This is probably the closest.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.