【问题标题】:C++ build error using librealsense in ubuntu在 ubuntu 中使用 librealsense 的 C++ 构建错误
【发布时间】:2020-04-06 15:21:44
【问题描述】:

我从源安装了librealsense。它已安装并成功构建。

当我尝试运行示例项目 (rs-hello-realsense) 时,我发现了构建错误。

/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'

来自不同类型的构建的相同类型的错误。

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'

【问题讨论】:

  • 你链接图书馆了吗?
  • 我需要在哪里链接库?当它构建时,它已经构建在 /use/local/ 中,我可以通过 include '#include ' 来使用它,不是吗?
  • 构建过程包含编译步骤和链接器步骤。在编译步骤中,头文件被添加到编译单元。在链接器步骤中,库被链接到您的工件中。您需要像-lLIBRARY 这样的链接器标志,可能像-lrealsense2 这样的东西。 gcc.gnu.org/onlinedocs/gcc/Link-Options.html

标签: c++ realsense


【解决方案1】:

终于明白了。需要在CMakeList.txt 中添加几行。 其中链接了项目中的库。

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

target_link_libraries(${PROJECT_NAME} ${realsense2_LIBRARY})

除了 CMake 文件的所有其他属性将相同

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多