RPath set wrong for executable in install folder (devel works)

asked 2020-03-23 07:57:21 -0500

Hi, I'm building a ROS node A that links against libtorch and some other libraries that I manage via conan. The CMakeLists.txt of A looks like this

make_minimum_required(VERSION 3.5)
project(A)

include(${REPOSITORY_BASE_PATH}/conanbuildinfo.cmake) # >>> Include the conanbuildinfo.cmake from my repos base
conan_basic_setup(TARGETS NO_OUTPUT_DIRS KEEP_RPATHS)

find_package(catkin REQUIRED COMPONENTS
...
)

# Collect source files
set(SRCS <All relevant source files>)

catkin_package(
...
)

add_library(${PROJECT_NAME} ${SRCS})    
target_link_libraries(${PROJECT_NAME}
    ...
    CONAN_PKG::libtorch # >>> This is libtorchs target defined by conan
    )

target_include_directories(${PROJECT_NAME}
    PUBLIC include/
    )

target_include_directories(${PROJECT_NAME}
    SYSTEM PUBLIC ${catkin_INCLUDE_DIRS}
    ${CONAN_INCLUDE_DIRS}
    )

add_executable(${PROJECT_NAME}_node src/main.cpp)
target_link_libraries(${PROJECT_NAME}_node ${PROJECT_NAME})

After running catkin_make install, I face the following problem:

  1. devel

If I run readelf -don the executable created for A in the devel folder, all necessary .so files are present and the rpath variable is set correctly. That is, I get output similar to this

Dynamic section at offset 0x11d68 contains 36 entries:
Tag        Type                         Name/Value
...
0x0000000000000001 (NEEDED)             Shared library: [libtorch.so]
...
0x000000000000000f (RPATH)              Library rpath: [<Correct paths>]
  1. install

For the executable created in the install folder however, the rpath is empty. That is, running readelf -d on the executable gives me something like

Dynamic section at offset 0x11d68 contains 36 entries:
Tag        Type                         Name/Value
...
0x0000000000000001 (NEEDED)             Shared library: [libtorch.so]
>>> No RPATH variable

Why is this happening and how can I fix it?

Thanks for any help in advance! :-)

Setup

I'm running ROS kinetic on x86 Ubuntu 16.04 and compile with gcc version 5.4.

edit retag flag offensive close merge delete