0
$\begingroup$

Rosanswers logo

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

Originally posted by David Lu on ROS Answers with karma: 10932 on 2018-11-01

Post score: 1


Original comments

Comment by gvdhoorn on 2018-11-01:
Unfortunately, GHFM doesn't work here :(

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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. ;)


Originally posted by allenh1 with karma: 3055 on 2018-11-01

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by David Lu on 2018-11-01:
That results in the same error.

Comment by allenh1 on 2018-11-01:
Ya, noticed a bit more for you to change, haha. See above.

Comment by David Lu on 2018-11-01:
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_example/tree/ros2auto Still gets the same linking error.

Comment by allenh1 on 2018-11-02:
Hey! I just went ahead and played around with it some. PR is on your repo, linked here for convenience.

Comment by David Lu on 2018-11-02:
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)

Comment by allenh1 on 2018-11-02:\

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.

Comment by allenh1 on 2018-11-02:
Also, I didn't see the PR comments...

Comment by David Lu on 2018-11-02:
Oops, forgot to submit my review. Done now.

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

Comment by David Lu on 2018-11-02:
Any hints @dirk-thomas?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.