ROS catkin build - 找不到共享库

问题描述 投票:0回答:1

我试图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/中,符号链接位于/ texplore / devel / lib /

我尝试了以下方法:

(1)export / texplore / devel / lib / to LD_LIBRARY_PATH

(2)将符号链接添加到/ 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/")

它没用。最后,我将符号链接添加到/ usr / local / lib并且它有效。但是我不想要这个文件夹中的符号链接。

因此,链接器根本不搜索构建树。我的问题是,为什么catkin没有在catkin_LIBRARIES中添加链接器路径?我之前已经构建了ROS软件包,但无法解决为什么这个特定软件包无法正常工作。

c++ linker ros catkin
1个回答
1
投票

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

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

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

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

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

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

  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)
    ...
© www.soinside.com 2019 - 2024. All rights reserved.