Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using ament_cmake and Vendor Libraries #551

Open
wimos-ai opened this issue Oct 9, 2024 · 1 comment
Open

Using ament_cmake and Vendor Libraries #551

wimos-ai opened this issue Oct 9, 2024 · 1 comment
Labels
more-information-needed Further information is required

Comments

@wimos-ai
Copy link

wimos-ai commented Oct 9, 2024

Hello, I am trying to get the ROS2 CMake build system to work with some vendor libraries. They basically distribute a set of shared libraries and some header files. The issue I am running into is dynamic linker errors, mainly because some of the Shared Objects depend on each other. Eg:

  • A.so
    -- B.so
    -- C.so

By playing with CMake Rpath rules, I can get my executable to link to A.so on Linux, but then on loading A.so cannot find B or C even though they are all in the same install directory due to Linux dynamic library search path rules. I could in theory use something like patchelf to point A.so to my install directory but that feels hacky. Is there a better way?

@mjcarroll
Copy link
Contributor

Could you potentially use the IMPORTED option from CMake in order for the library to be correctly registered as a cmake target?

Something like:

# Set the path to the external vendor project
set(VENDOR_PROJECT_DIR "/path/to/vendor/project")

# Import libA.so
add_library(libA SHARED IMPORTED)
set_target_properties(libA PROPERTIES
  IMPORTED_LOCATION "${VENDOR_PROJECT_DIR}/lib/libA.so"
  INTERFACE_LINK_LIBRARIES libB libC
)

# Import libB.so
add_library(libB SHARED IMPORTED)
set_target_properties(libB PROPERTIES
  IMPORTED_LOCATION "${VENDOR_PROJECT_DIR}/lib/libB.so"
)

# Import libC.so
add_library(libC SHARED IMPORTED)
set_target_properties(libC PROPERTIES
  IMPORTED_LOCATION "${VENDOR_PROJECT_DIR}/lib/libC.so"
)

Then you can use the libraries by doing:

target_link_libraries(my_executable PRIVATE libA libB libC) 

@cottsay cottsay added the more-information-needed Further information is required label Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more-information-needed Further information is required
Projects
None yet
Development

No branches or pull requests

3 participants