realsense-ros: undefined symbol: _ZN2cv3MatC1Ev

I have done a source build of realsense-ros and librealsense (native backend + CUDA, but SKIPPING the kernel patches) on a nvidia AGX Orin. It was suggested here that this might work. I am getting undefined symbol: _ZN2cv3MatC1Ev when trying to launch.

Output of uname -a

Linux orin-devkit 5.10.65-tegra #1 SMP PREEMPT Mon May 16 20:58:07 PDT 2022 aarch64 aarch64 aarch64 GNU/Linux

Output with launching rs_rgbd.launch or rs_camera.launch

[ INFO] [1662238035.921341031]: Done Setting Dynamic reconfig parameters.
/opt/ros/noetic/lib/nodelet/nodelet: symbol lookup error: /home/sacvp-user/git/scaled-acv/sacvp/on-the-device/ros/devel/lib//librealsense2_camera.so: undefined symbol: _ZN2cv3MatC1Ev
[camera/realsense2_camera_manager-4] process has died [pid 2467862, exit code 127, cmd /opt/ros/noetic/lib/nodelet/nodelet manager __name:=realsense2_camera_manager __log:=/home/sacvp-user/.ros/log/93f38000-2bc9-11ed-a8a8-ec63d76dedb8/camera-realsense2_camera_manager-4.log].
log file: /home/sacvp-user/.ros/log/93f38000-2bc9-11ed-a8a8-ec63d76dedb8/camera-realsense2_camera_manager-4*.log
[camera/points_xyzrgb_hw_registered-7] process has finished cleanly

I think this might be related.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 29

Most upvoted comments

I think I’ve solved this through a combination of

  • not making typos in CMakeLists.txt
  • understanding ros/catkin workspace sourcing better
  • compiling opencv properly (my script is basically the same as mdegans)

I don’t have any clear learnings to share, but the problem is solved.

For the record heres what I did

  1. Compiled opencv with CUDA, but no GTK, QT, or opengl support ( those lead to a different unrelated opencv compilation error, I cannot get opencv later than 4.5.0 to compile with opengl and GUI features on my orin due undefined reference to glXGetProcAddressARB() )
  2. build librealsense with native backend and cuda, without patching the kernel.
  3. included realsense-ros in my projects catkin workspace
  4. modified realsense-ros CMakeLists.txt to find opencv and include it as per here
  5. catkin_make’d it and sourced the workspace properly.

Additionally, I

  • made sure librealsense was not installed from apt. At one point I had run make, but not sudo make install. Removing the apt version of librealsense just avoided confusion as to which one was running.
  • made sure ros-noetic-realsense-ros was not installed from apt, for the same reason.

It is possible that between having apt installed versions, workspace sourcing, etc that I was not running the compiled version of librealsense.

Anyay, the changes to realsense-ros CMakeLists.txt works.

OK, yes I picked that up after re-reading the instructions. I proceed with the packages installed for graphical examples.

I added: find_package( OpenCV REQUIRED)

and modified:

include_directories(
    include
    ${realsense2_INCLUDE_DIR}
    ${catkin_INCLUDE_DIRS}
    ${OpenCV_INCLUDE_DIRS}
    )
target_link_libraries(${PROJECT_NAME}
    ${realsense2_LIBRARY}
    ${catkin_LIBRARIES}
    ${CMAKE_THREAD_LIBS_INIT}
    #{OpenCV_LIBRARIES}
    )

But I still have this error when launching rs_rgbd.

In the realsense2_camera build output everything looks normal except for:

-- Set runtime path of "/home/sacvp-user/catkin_ws/install/lib/librealsense2_camera.so" to ""

It is the right track though, OpenCV is not being linked.

My full realsense2_camera CMakeLists:

cmake_minimum_required(VERSION 2.8.3)
project(realsense2_camera)
add_compile_options(-std=c++11)

option(BUILD_WITH_OPENMP "Use OpenMP" OFF)
option(SET_USER_BREAK_AT_STARTUP "Set user wait point in startup (for debug)" OFF)

add_definitions(-D_CRT_SECURE_NO_WARNINGS)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

find_package(catkin REQUIRED COMPONENTS
    message_generation
    nav_msgs
    roscpp
    sensor_msgs
    std_msgs
    std_srvs
    nodelet
    cv_bridge
    image_transport
    tf
    ddynamic_reconfigure
    diagnostic_updater
    )

find_package(OpenCV REQUIRED)

if(BUILD_WITH_OPENMP)
    find_package(OpenMP)
    if(NOT OpenMP_FOUND)
        message(FATAL_ERROR "\n\n OpenMP is missing!\n\n")
    else()
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS} -fopenmp")
        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
    endif()
endif()

if(SET_USER_BREAK_AT_STARTUP)
	message("GOT FLAG IN CmakeLists.txt")
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBPDEBUG")
endif()

if (WIN32)
find_package(realsense2 CONFIG REQUIRED)
else()
find_package(realsense2 2.50.0)
endif()

if(NOT realsense2_FOUND)
    message(FATAL_ERROR "\n\n Intel RealSense SDK 2.0 is missing, please install it from https://github.com/IntelRealSense/librealsense/releases\n\n")
endif()

if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release)
endif()

string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
if (${uppercase_CMAKE_BUILD_TYPE} STREQUAL "RELEASE")
    message(STATUS "Create Release Build.")
    set(CMAKE_CXX_FLAGS "-O2 ${CMAKE_CXX_FLAGS}")
else()
    message(STATUS "Create Debug Build.")
endif()

if (WIN32)
else()
set(CMAKE_CXX_FLAGS "-fPIE -fPIC -std=c++11 -D_FORTIFY_SOURCE=2 -fstack-protector -Wformat -Wformat-security -Wall ${CMAKE_CXX_FLAGS}")
endif()

add_message_files(
    FILES
    IMUInfo.msg
    Extrinsics.msg
    Metadata.msg
    )

add_service_files(
    FILES
    DeviceInfo.srv
)

generate_messages(
    DEPENDENCIES
    sensor_msgs
    std_msgs
    )

set(CMAKE_NO_SYSTEM_FROM_IMPORTED true)
include_directories(
    include
    ${realsense2_INCLUDE_DIR}
    ${catkin_INCLUDE_DIRS}
    ${OpenCV_INCLUDE_DIRS}
    )

# RealSense ROS Node
catkin_package(
    LIBRARIES ${PROJECT_NAME}
    CATKIN_DEPENDS message_runtime roscpp sensor_msgs std_msgs
    nodelet
    cv_bridge
    image_transport
    ddynamic_reconfigure
    nav_msgs
    )

add_library(${PROJECT_NAME}
    include/constants.h
    include/realsense_node_factory.h
    include/base_realsense_node.h
    include/t265_realsense_node.h
    src/realsense_node_factory.cpp
    src/base_realsense_node.cpp
    src/t265_realsense_node.cpp
    )

add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}_generate_messages_cpp)
add_dependencies(${PROJECT_NAME} ${catkin_EXPORTED_TARGETS})

target_include_directories(${PROJECT_NAME}
  PRIVATE ${realsense2_INCLUDE_DIR})

target_link_libraries(${PROJECT_NAME}
    ${realsense2_LIBRARY}
    ${catkin_LIBRARIES}
    ${CMAKE_THREAD_LIBS_INIT}
    #{OpenCV_LIBRARIES}
    )

if(WIN32)
set_target_properties(${realsense2_LIBRARY} PROPERTIES MAP_IMPORTED_CONFIG_RELWITHDEBINFO RELEASE)
target_link_libraries(${PROJECT_NAME}
    realsense2::realsense2 
    realsense2::realsense-file
    )
endif()


# Install nodelet library
install(TARGETS ${PROJECT_NAME}
    ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
    LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
    RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
    )

# Install header files
install(DIRECTORY include/
    DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
    )

# Install launch files
install(DIRECTORY launch/
    DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch
    )

# Install rviz files
install(DIRECTORY rviz/
    DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/rviz
    )

# Install xml files
install(FILES nodelet_plugins.xml
    DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
    )