Search code examples
c++realsense

C++ build error using librealsense in ubuntu


I installed librealsense from the source. It was installed and build successfully.

When I tried to run the sample project (rs-hello-realsense) I have found the build error.

/usr/local/include/librealsense2/hpp/rs_types.hpp:90: undefined reference to `rs2_get_error_message'
/usr/local/include/librealsense2/hpp/rs_types.hpp:92: undefined reference to `rs2_get_failed_function'
/usr/local/include/librealsense2/hpp/rs_types.hpp:92: undefined reference to `rs2_get_failed_function'

Same kind of error from a different type of build.

CMakeFiles/rs-hello-realsense.dir/rs-hello-realsense.cpp.o: In function `rs2::error::error(rs2_error*)':
rs-hello-realsense.cpp:(.text._ZN3rs25errorC2EP9rs2_error[_ZN3rs25errorC5EP9rs2_error]+0x2e): undefined reference to `rs2_get_error_message'
rs-hello-realsense.cpp:(.text._ZN3rs25errorC2EP9rs2_error[_ZN3rs25errorC5EP9rs2_error]+0x73): undefined reference to `rs2_get_failed_function'

Solution

  • Finally, get it. Need to add a couple of lines in CMakeList.txt. Which linked the libraries in the project.

    find_package(realsense2 2.29.0)
    target_link_libraries(rs-hello-realsense ${DEPENDENCIES} ${realsense2_LIBRARY})
    

    OR

    target_link_libraries(${PROJECT_NAME} ${realsense2_LIBRARY})
    

    Other than all other properties of CMake File will be same