gpt4 book ai didi

c++ - ROS catkin build - 找不到共享库

转载 作者:行者123 更新时间:2023-11-28 04:26:09 29 4
gpt4 key购买 nike

我正在尝试用 catkin 构建这个 ROS 包 https://github.com/toddhester/rl-texplore-ros-pkg但它无法构建“rl_experiment”并出现以下错误:

/usr/bin/ld: cannot find -lagentlib
/usr/bin/ld: cannot find -lenvlib
collect2: error: ld returned 1 exit status

我正在使用 ROS Kinetic。共享库确实存在于文件夹/texplore/devel/.private/rl_env/lib/和/texplore/devel/.private/rl_agent/lib/中,符号链接(symbolic link)位于/texplore/devel/lib/

我尝试了以下方法:

(1) 导出/texplore/devel/lib/到 LD_LIBRARY_PATH

(2) 添加符号链接(symbolic link)到/texplore/src/rl_experiment/src 中的库

(3) 添加库路径到target_link_libraries

target_link_libraries(experiment agentlib envlib ${catkin_LIBRARIES} 
"/media/usr/texplore/devel/lib/libagentlib.so"
"/media/usr/texplore/devel/lib/libenvlib.so")

(4) 设置链接器的搜索路径

SET(CMAKE_EXE_LINKER_FLAGS 
"${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath -Wl,/media/usr/texplore/devel/lib/")

它没有用。最后,我将符号链接(symbolic link)添加到/usr/local/lib 并且它起作用了。但我不想要此文件夹中的符号链接(symbolic link)。

所以链接器根本没有搜索构建树。我的问题是,为什么catkin没有在catkin_LIBRARIES中添加链接器路径?我以前构建过 ROS 包,但无法理解为什么这个特定包不起作用。

最佳答案

我遇到了同样的问题。我根据this post做了以下修改关于 ROS Answers 和通用 CMakeLists.txt 文件中 catkin_packages 宏的以下注释:

## LIBRARIES: libraries you create in this project that dependent projects also need

我做了一些事情来解决这个问题......

  1. 已添加LIBRARIES agentlibrl_agent/CMakeLists.txt 文件中的 catkin_packages 宏。这使得 agentlib 库稍后可用于 rl_experiment
  2. LIBRARIES envlib 添加到 rl_env/CMakeLists.txt 文件中的 catkin_packages 宏。这使得 envlib 库稍后可用于 rl_experiment
  3. rl_experiment/CMakeLists.txt 文件的 target_link_libraries 宏中删除了 agentlibenvlib。这些都不是必需的。
  4. 已验证的 rl_agentrl_env 包列在 rl_experiment/CMakeLists.txtfind_package 宏中。

...然后一切都成功编译。

添加片段以进一步说明...

  1. rl_agent CMakeLists.TXT 更改(上述第 1 项):
    ...

## Declare a cpp library
# add_library(rgbd_tools
# src/${PROJECT_NAME}/
# )

add_library(agentlib
src/Agent/DiscretizationAgent.cc
src/Agent/QLearner.cc
...
src/newmat/newmatrm.cc
src/newmat/newmat9.cc
)

## Declare a cpp executable
# add_executable(rgbd_tools_node src/rgbd_tools_node.cpp)

...
  1. rl_env CMakeLists.txt 更改(上述第 2 项):
    ...
###################################
## catkin specific configuration ##
###################################
...
catkin_package(
INCLUDE_DIRS include
LIBRARIES envlib
# CATKIN_DEPENDS roscpp rospy std_msgs
CATKIN_DEPENDS message_runtime
# DEPENDS system_lib
)

...
  1. rl_experiment CMakeLists.txt 更改(上述第 3 项和第 4 项):
    ...
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
roscpp
std_msgs
rl_common
rl_env
rl_agent
)

## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
...
## Declare a cpp executable
# add_executable(rgbd_tools_node src/rgbd_tools_node.cpp)

add_executable(experiment src/rl.cc)
# target_link_libraries(experiment agentlib envlib ${catkin_LIBRARIES})
target_link_libraries(experiment ${catkin_LIBRARIES})

#add_executable(image_converter src/image_converter.cpp)
...

关于c++ - ROS catkin build - 找不到共享库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54271001/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com