ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

ROS2 Linking

asked 2018-11-01 10:52:38 -0500

David Lu gravatar image

updated 2018-11-02 11:11:58 -0500

I'm having trouble linking libraries in ROS2. I have a simple example posted here

I have two packages. awesome_library defines a C++ class in a library and fantastic_node defines a C++ executable that instantiates the class from awesome_library.

I am familiar with how to do this in ROS1, but in ROS2 I am getting the following error.

[ 50%] Linking CXX executable fantastic_node_node
CMakeFiles/fantastic_node_node.dir/src/fnode.cpp.o: In function `main':
fnode.cpp:(.text+0x17d): undefined reference to `awesome_library::Awesomeness::Awesomeness()'
collect2: error: ld returned 1 exit status
CMakeFiles/fantastic_node_node.dir/build.make:177: recipe for target 'fantastic_node_node' failed
make[2]: *** [fantastic_node_node] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/fantastic_node_node.dir/all' failed

From the command ament build --only-packages awesome_library fantastic_node

I've tried a couple different variations of the library installation in awesome_library and target linking in fantastic_node but have not found one that works, or a similar example.

Current attempts with allenh1's branch:

ros-bouncy-ament-tools:
  Installed: 0.5.0-0bionic.20180719.223430
  Candidate: 0.5.0-0bionic.20180719.223430
  Version table:
 *** 0.5.0-0bionic.20180719.223430 500
        500 http://repo.ros2.org/ubuntu/main bionic/main amd64 Packages
        100 /var/lib/dpkg/status
! ros2_ws/ > apt-cache policy python3-colcon-core 
python3-colcon-core:
  Installed: 0.3.12-1
  Candidate: 0.3.12-1
  Version table:
 *** 0.3.12-1 500
        500 http://repo.ros2.org/ubuntu/main bionic/main amd64 Packages
        500 http://repo.ros2.org/ubuntu/main bionic/main arm64 Packages
        100 /var/lib/dpkg/status
! ros2_ws/ > colcon build --packages-select awesome_library fantastic_node --symlink-install
Starting >>> awesome_library
Finished <<< awesome_library [0.27s]                       
Starting >>> fantastic_node
--- stderr: fantastic_node                             
CMakeFiles/fantastic_node_node.dir/src/fnode.cpp.o: In function `main':
fnode.cpp:(.text+0x17d): undefined reference to `awesome_library::Awesomeness::Awesomeness()'
collect2: error: ld returned 1 exit status
make[2]: *** [fantastic_node_node] Error 1
make[1]: *** [CMakeFiles/fantastic_node_node.dir/all] Error 2
make: *** [all] Error 2
---
Failed   <<< fantastic_node [ Exited with code 2 ]

Summary: 1 package finished [0.75s]
  1 package failed: fantastic_node
  1 package had stderr output: fantastic_node
[0.860s] ERROR:colcon.colcon_notification.desktop_notification:Exception in desktop notification extension 'notify2': org.freedesktop.Notifications.MaxNotificationsExceeded: Exceeded maximum number of notifications
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/colcon_notification/desktop_notification/__init__.py", line 107, in notify
    title=title, message=message, icon_path=icon_path)
  File "/usr/lib/python3/dist-packages/colcon_notification/desktop_notification/notify2.py", line 50, in notify
    self._last_notification.show()
  File "/usr/lib/python3/dist-packages/notify2.py", line 188, in show
    self.timeout,  # expire_timeout
  File "/usr/lib/python3/dist-packages/dbus/proxies.py", line 70, in __call__
    return self._proxy_method(*args, **keywords)
  File "/usr/lib/python3/dist-packages/dbus/proxies.py", line 145, in __call__
    **keywords)
  File "/usr/lib/python3/dist-packages/dbus/connection.py", line 651, in call_blocking
    message, timeout)
dbus.exceptions.DBusException: org.freedesktop.Notifications.MaxNotificationsExceeded: Exceeded maximum number of notifications
edit retag flag offensive close merge delete

Comments

Unfortunately, GHFM doesn't work here :(

gvdhoorn gravatar image gvdhoorn  ( 2018-11-01 11:20:17 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2018-11-01 14:07:39 -0500

allenh1 gravatar image

updated 2018-11-01 14:37:02 -0500

you should probably use colcon if you're using bouncy:

colcon build --packages-select awesome_library fantastic_node

Edit: upon further review, I see you're linking to ${catkin_LIBRARIES}, which you probably shouldn't be doing.

In my ports, I usually do a

set(req_deps
  "rclcpp"
  # other libs
)

then, in lieu of ${catkin_LIBRARIES}, I would do this:

ament_auto_find_build_dependencies(REQUIRED ${req_deps})

and this

ament_auto_add_library(awesomeness src/aswesome.cpp)
ament_target_dependencies(awesomeness ${req_deps})

For an example of libraries, I'll point you to my openslam_gmapping port, and for a very minimal port (so you can see the whole diff), I'll point you to a port of rplidar_ros I did recently.

I'm sure I forgot something above, so let me know what it was. ;)

edit flag offensive delete link more

Comments

That results in the same error.

David Lu gravatar image David Lu  ( 2018-11-01 14:23:37 -0500 )edit

Ya, noticed a bit more for you to change, haha. See above.

allenh1 gravatar image allenh1  ( 2018-11-01 14:37:18 -0500 )edit

Okay, I've tried porting to ament_auto (of which there are few examples/documents that I've found). Results are in this branch: https://github.com/DLu/simple_ros2_ex... Still gets the same linking error.

David Lu gravatar image David Lu  ( 2018-11-01 14:53:53 -0500 )edit

Hey! I just went ahead and played around with it some. PR is on your repo, linked here for convenience.

allenh1 gravatar image allenh1  ( 2018-11-02 09:59:58 -0500 )edit

I tried your branch and it didn't work (see comments on the PR). It also seems like there should be a way to do it without ament_auto (since the migration guide and examples don't use it)

David Lu gravatar image David Lu  ( 2018-11-02 10:51:12 -0500 )edit

I tried your branch and it didn't work

:( It definitely worked on my machine. Did you invoke colcon with --symlink-install?

do it without ament_auto

that makes sense. @dirk-thomas can you please explain what ament_auto is? I've forgotten the difference.

allenh1 gravatar image allenh1  ( 2018-11-02 10:55:08 -0500 )edit

Also, I didn't see the PR comments...

allenh1 gravatar image allenh1  ( 2018-11-02 10:56:07 -0500 )edit

Oops, forgot to submit my review. Done now.

I've updated the above with some of the pertinent version info, exact command and output.

David Lu gravatar image David Lu  ( 2018-11-02 11:10:18 -0500 )edit
0

answered 2018-11-05 11:14:16 -0500

Dirk Thomas gravatar image

See https://github.com/ros2/ros2/issues/598 for the duplicate issue and the answer what is wrong in the example packages.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2018-11-01 10:52:38 -0500

Seen: 2,781 times

Last updated: Nov 05 '18