ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A answers.ros.org

Library not loaded: libfastcdr.dylib

Operating System: OSX 10.12.5
Installation type: binary
Version or commit hash: beta 1; version: 148df7e841b91da488ec3bb4abd295a2bccdb728
DDS implementation: Fast-RTPS
Client library (if applicable): boost, restcpp

Steps to reproduce issue
ament test --only-packages skynet

Expected behavior
test runs normally

Actual behavior
Failed with output:

+++ Testing 'skynet'
==> '. /Users/mc/skynet-edge/core_ws/build/skynet/cmake__test.sh && /usr/bin/make test ARGS=-V -D ExperimentalTest --no-compress-output' in '/Users/mc/skynet-edge/core_ws/build/skynet'
Running tests...
UpdateCTestConfiguration  from :/Users/mc/skynet-edge/core_ws/build/skynet/DartConfiguration.tcl
Parse Config file:/Users/mc/skynet-edge/core_ws/build/skynet/DartConfiguration.tcl
   Site: mcs-MacBook-Pro.sjc.cyngn.internal
   Build name: Darwin-c++
 Add coverage exclude regular expressions.
SetCTestConfiguration:CMakeCommand:/Applications/CMake.app/Contents/bin/cmake
UpdateCTestConfiguration  from :/Users/mc/skynet-edge/core_ws/build/skynet/DartConfiguration.tcl
Parse Config file:/Users/mc/skynet-edge/core_ws/build/skynet/DartConfiguration.tcl
Test project /Users/mc/skynet-edge/core_ws/build/skynet
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 1
    Start 1: skynet_test

1: Test command: /usr/local/bin/python3 "-u" "/Users/mc/ros2-osx/share/ament_cmake_test/cmake/run_test.py" "/Users/mc/skynet-edge/core_ws/build/skynet/test_results/skynet/skynet_test.gtest.xml" "--output-file" "/Users/mc/skynet-edge/core_ws/build/skynet/ament_cmake_gmock/skynet_test.txt" "--command" "/Users/mc/skynet-edge/core_ws/build/skynet/test/skynet_test" "--gtest_output=xml:/Users/mc/skynet-edge/core_ws/build/skynet/test_results/skynet/skynet_test.gtest.xml"
1: Test timeout computed to be: 60
1: -- run_test.py: invoking following command in '/Users/mc/skynet-edge/core_ws/src/skynet':
1:  - /Users/mc/skynet-edge/core_ws/build/skynet/test/skynet_test --gtest_output=xml:/Users/mc/skynet-edge/core_ws/build/skynet/test_results/skynet/skynet_test.gtest.xml
1: dyld: Library not loaded: libfastcdr.dylib
1:   Referenced from: /Users/mc/ros2-osx/lib/librmw_fastrtps_cpp.dylib
1:   Reason: image not found
1: -- run_test.py: return code -6
1: -- run_test.py: generate result file '/Users/mc/skynet-edge/core_ws/build/skynet/test_results/skynet/skynet_test.gtest.xml' with failed test
1: -- run_test.py: verify result file '/Users/mc/skynet-edge/core_ws/build/skynet/test_results/skynet/skynet_test.gtest.xml'
1/1 Test #1: skynet_test ......................***Failed    0.14 sec

0% tests passed, 1 tests failed out of 1

Label Time Summary:
gmock    =   0.14 sec (1 test)

Total Test time (real) =   0.14 sec

The following tests FAILED:
      1 - skynet_test (Failed)
Errors while running CTest
make: *** [test] Error 8

<== Command '. /Users/mc/skynet-edge/core_ws/build/skynet/cmake__test.sh && /usr/bin/make test 'ARGS=-V -D ExperimentalTest --no-compress-output'' failed in '/Users/mc/skynet-edge/core_ws/build/skynet' with exit code '2'

Additional information
My project compiles fine. I created a ROS2 test for my project and want to run it. The same test works fine on Ubuntu. I only have this problem on OSX.

As message says, the system can’t find libfastcdr.dylib. That is weird, because I can see the library in ~/ros2-osx/lib dir. I assume it should be visible after I sourced ROS2. I tried source scripts setup.bash, setup.sh, local_setup.bash, local_setup.sh. Nothing helped.

If I manually create symbol link in /usr/local/lib pointing to ~/ros2-osx/lib/libfastcdr.dylib, everything works fine. It doesn’t feels the right fix though.

Could someone hint how should it work normally?

That could be an issue with how Fast-RTPS is being linked. It sounds like it isn’t using RPATH and it should be.

Even without RPATH it should work if ~/ros2-osx/lib is in your DYLD_LIBRARY_PATH environment variable after you source ~/ros2-osx/setup.bash (this is the right one to source in most cases). If it is in the variable, then you may have SIP enabled which is a security feature in macOS that prevents propagation of the DYLD_LIBRARY_PATH to “system” binaries, like bash and make, which reside in /usr/bin and similar PATH folders.

If it is SIP then you can disable it (not recommended for security, but will work around the issue):

I might be reading the log incorrectly, but near the top it says “beta 1.” Lots has changed since then (6 months ago) in both ROS 2 and Fast-RTPS; you might want to try Beta 2 and see if the issue goes away.

@wjwwood
Not sure what is RPATH. Is it env. variable? I can’t see this variable set after I sourced ~/ros2-osx/setup.bash.
I tried to set DYLD_LIBRARY_PATH manually but, as you said, it isn’t helping due to SIP.

@codebot
Tried it with ROS2 beta2. Message is changed a bit but problem remains the same.

Running tests...
UpdateCTestConfiguration  from :/Users/mc/skynet-edge/core_ws/build/skynet/DartConfiguration.tcl
Parse Config file:/Users/mc/skynet-edge/core_ws/build/skynet/DartConfiguration.tcl
   Site: mcs-MacBook-Pro.sjc.cyngn.internal
   Build name: Darwin-c++
 Add coverage exclude regular expressions.
SetCTestConfiguration:CMakeCommand:/Applications/CMake.app/Contents/bin/cmake
Create new tag: 20170712-1754 - Experimental
UpdateCTestConfiguration  from :/Users/mc/skynet-edge/core_ws/build/skynet/DartConfiguration.tcl
Parse Config file:/Users/mc/skynet-edge/core_ws/build/skynet/DartConfiguration.tcl
Test project /Users/mc/skynet-edge/core_ws/build/skynet
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 1
    Start 1: skynet_test

1: Test command: /usr/local/bin/python3 "-u" "/Users/mc/ros2-osx-b2/share/ament_cmake_test/cmake/run_test.py" "/Users/mc/skynet-edge/core_ws/build/skynet/test_results/skynet/skynet_test.gtest.xml" "--output-file" "/Users/mc/skynet-edge/core_ws/build/skynet/ament_cmake_gmock/skynet_test.txt" "--command" "/Users/mc/skynet-edge/core_ws/build/skynet/test/skynet_test" "--gtest_output=xml:/Users/mc/skynet-edge/core_ws/build/skynet/test_results/skynet/skynet_test.gtest.xml"
1: Test timeout computed to be: 60
1: -- run_test.py: invoking following command in '/Users/mc/skynet-edge/core_ws/src/skynet':
1:  - /Users/mc/skynet-edge/core_ws/build/skynet/test/skynet_test --gtest_output=xml:/Users/mc/skynet-edge/core_ws/build/skynet/test_results/skynet/skynet_test.gtest.xml
1: dyld: Library not loaded: libfastrtps.1.dylib
1:   Referenced from: /Users/mc/skynet-edge/core_ws/build/skynet/test/skynet_test
1:   Reason: image not found
1: -- run_test.py: return code -6
1: -- run_test.py: generate result file '/Users/mc/skynet-edge/core_ws/build/skynet/test_results/skynet/skynet_test.gtest.xml' with failed test
1: -- run_test.py: verify result file '/Users/mc/skynet-edge/core_ws/build/skynet/test_results/skynet/skynet_test.gtest.xml'
1/1 Test #1: skynet_test ......................***Failed    0.17 sec

0% tests passed, 1 tests failed out of 1

Label Time Summary:
gmock    =   0.17 sec (1 test)

Total Test time (real) =   0.18 sec

The following tests FAILED:
      1 - skynet_test (Failed)
Errors while running CTest
make: *** [test] Error 8

<== Command '. /Users/mc/skynet-edge/core_ws/build/skynet/cmake__test.sh && /usr/bin/make test 'ARGS=-V -D ExperimentalTest --no-compress-output'' failed in '/Users/mc/skynet-edge/core_ws/build/skynet' with exit code '2'
'test_pkg' for package '/Users/mc/skynet-edge/core_ws/src/skynet' failed: <== Command '. /Users/mc/skynet-edge/core_ws/build/skynet/cmake__test.sh && /usr/bin/make test 'ARGS=-V -D ExperimentalTest --no-compress-output'' failed in '/Users/mc/skynet-edge/core_ws/build/skynet' with exit code '2'
<== Command '. /Users/mc/skynet-edge/core_ws/build/skynet/cmake__test.sh && /usr/bin/make test 'ARGS=-V -D ExperimentalTest --no-compress-output'' failed in '/Users/mc/skynet-edge/core_ws/build/skynet' with exit code '2'

Is there anything else I can try to fix it?

RPATH is something that is contained within shared libraries, see:

You could try using install_name_tool to change the libfastrtps.1.dylib reference in your /Users/mc/skynet-edge/core_ws/build/skynet/test/skynet_test executable to be /Users/mc/ros2-osx/lib/libfastrtps.1.dylib, or what ever the actual path is.

I finally fixed it by adding these lines to my CMakeLists.txt

...
#ROS2 beta1
SET(ROS_LIBRARIES_DIR "${ament_cmake_DIR}/../../../lib")
#ROS2 beta2
#SET(ROS_LIBRARIES_DIR "${fastcdr_LIB_DIR}")
...
ament_add_gmock(${PROJECT_NAME}_test
        MyTestName.cpp
        APPEND_LIBRARY_DIRS "${ROS_LIBRARIES_DIR}" 
)

I’m glad you got it working, but it shouldn’t be necessary I think. It’s probably either a bug in the CMake module for Fast-RTPS or in how we pass along, or link to, those libraries in rmw_fastrtps_cpp.

I’ll see if I can look into later.