micro-ROS / micro-ROS-demos

Sample code using rclc and rclcpp implementations.
Apache License 2.0
84 stars 24 forks source link

Problems building Ping Pong Demo #43

Closed torbenf closed 3 years ago

torbenf commented 3 years ago

Hey I have problems building the Ping Pong example from https://micro.ros.org/docs/tutorials/core/first_application_linux/ the following error

--- stderr: microxrcedds_agent                                                                  
/usr/bin/ld: /usr/local/lib/libspdlog.a(spdlog.cpp.o): relocation R_X86_64_TPOFF32 against `_ZGVZN6spdlog7details2os9thread_idEvE3tid' can not be used when making a shared object; recompile with -fPIC

occurs during building the firmware and building the agent.

I hope somebody can help me with this because I don't know how to resolve this error.

Setup

Steps to reproduce the issue

Following the Tutorial on https://micro.ros.org/docs/tutorials/core/first_application_linux/ and building the firmware with

# Build step 
ros2 run micro_ros_setup build_firmware.sh
source install/local_setup.bash

and then downloading and building the agent

# Download micro-ROS-Agent packages
ros2 run micro_ros_setup create_agent_ws.sh
# Build step
ros2 run micro_ros_setup build_agent.sh
source install/local_setup.bash`

Expected behavior

I expected everything to build fine and be able to do a

# Run a micro-ROS agent
ros2 run micro_ros_agent micro_ros_agent udp4 --port 8888

afterwards.

Actual behavior

ros2 run micro_ros_setup build_firmware.sh produced:

--- stderr: microxrcedds_agent                                                                  
/usr/bin/ld: /usr/local/lib/libspdlog.a(spdlog.cpp.o): relocation R_X86_64_TPOFF32 against `_ZGVZN6spdlog7details2os9thread_idEvE3tid' can not be used when making a shared object; recompile with -fPIC
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/microxrcedds_agent.dir/build.make:676: libmicroxrcedds_agent.so.2.0.0] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/microxrcedds_agent.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
---
Failed   <<< microxrcedds_agent [0.44s, exited with code 2]
Aborted  <<< rmw_microxrcedds [0.49s]

Summary: 14 packages finished [11.4s]
  1 package failed: microxrcedds_agent
  1 package aborted: rmw_microxrcedds
  1 package had stderr output: microxrcedds_agent
  24 packages not processed

and ros2 run micro_ros_setup build_agent.sh produced

Building micro-ROS Agent
Starting >>> microcdr
Starting >>> builtin_interfaces
Finished <<< microcdr [0.26s]                                                                   
Starting >>> microxrcedds_agent
--- stderr: microxrcedds_agent                                         
/usr/bin/ld: /usr/local/lib/libspdlog.a(spdlog.cpp.o): relocation R_X86_64_TPOFF32 against `_ZGVZN6spdlog7details2os9thread_idEvE3tid' can not be used when making a shared object; recompile with -fPIC
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/microxrcedds_agent.dir/build.make:676: libmicroxrcedds_agent.so.2.0.0] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/microxrcedds_agent.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
---
Failed   <<< microxrcedds_agent [0.45s, exited with code 2]
Aborted  <<< builtin_interfaces [0.99s]                           

Summary: 1 package finished [1.19s]
  1 package failed: microxrcedds_agent
  1 package aborted: builtin_interfaces
  1 package had stderr output: microxrcedds_agent
  3 packages not processed

Because the above failed I can't run ros2 run micro_ros_agent micro_ros_agent udp4 --port 8888

Additional information

I am happy to provide additional Information if needed.

Thank you very much!

ralph-lange commented 3 years ago

Just because we had recently an issue with spdlog and clang (cf. https://github.com/micro-ROS/micro-ROS-Agent/issues/54): Which compiler are you using?

ralph-lange commented 3 years ago

The problem seems to be the /usr/local/lib/libspdlog.a. Normally, it is built during ros2 run micro_ros_setup build_agent.sh inside the workspace and this version is used for linking the agent executable. Can you please check whether there is a libspdlog.a in [your_micro-ROS_workspace]/build using find . -name libspdlog.a?

torbenf commented 3 years ago

gcc --version yields: gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0

and

g++ --version g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0

dpkg --list | grep compiler gives me:

ii  clang                                       1:10.0-50~exp1                       amd64        C, C++ and Objective-C compiler (LLVM based)
ii  clang-10                                    1:10.0.0-4ubuntu1                    amd64        C, C++ and Objective-C compiler
ii  g++                                         4:9.3.0-1ubuntu2                     amd64        GNU C++ compiler
ii  g++-9                                       9.3.0-17ubuntu1~20.04                amd64        GNU C++ compiler
ii  gcc                                         4:9.3.0-1ubuntu2                     amd64        GNU C compiler
ii  gcc-7                                       7.5.0-6ubuntu2                       amd64        GNU C compiler
ii  gcc-8                                       8.4.0-3ubuntu2                       amd64        GNU C compiler
ii  gcc-9                                       9.3.0-17ubuntu1~20.04                amd64        GNU C compiler
ii  gfortran                                    4:9.3.0-1ubuntu2                     amd64        GNU Fortran 95 compiler
ii  gfortran-8                                  8.4.0-3ubuntu2                       amd64        GNU Fortran compiler
ii  gfortran-9                                  9.3.0-17ubuntu1~20.04                amd64        GNU Fortran compiler
ii  libllvm10:amd64                             1:10.0.0-4ubuntu1                    amd64        Modular compiler and toolchain technologies, runtime library
ii  libllvm11:amd64                             1:11.0.0-2~ubuntu20.04.1             amd64        Modular compiler and toolchain technologies, runtime library
ii  libllvm6.0:amd64                            1:6.0.1-14                           amd64        Modular compiler and toolchain technologies, runtime library
ii  libluajit-5.1-2:amd64                       2.1.0~beta3+dfsg-5.1build1           amd64        Just in time compiler for Lua - library version
ii  libluajit-5.1-common                        2.1.0~beta3+dfsg-5.1build1           all          Just in time compiler for Lua - common files
ii  libparams-validationcompiler-perl           0.30-1                               all          module to build an optimized subroutine parameter validator
ii  libprotoc-dev:amd64                         3.6.1.3-2ubuntu5                     amd64        protocol buffers compiler library (development files)
ii  libprotoc17:amd64                           3.6.1.3-2ubuntu5                     amd64        protocol buffers compiler library
ii  libxkbcommon-dev:amd64                      0.10.0-1                             amd64        library interface to the XKB compiler - development files
ii  libxkbcommon0:amd64                         0.10.0-1                             amd64        library interface to the XKB compiler - shared library
ii  llvm-10                                     1:10.0.0-4ubuntu1                    amd64        Modular compiler and toolchain technologies
ii  llvm-10-dev                                 1:10.0.0-4ubuntu1                    amd64        Modular compiler and toolchain technologies, libraries and headers
ii  llvm-10-runtime                             1:10.0.0-4ubuntu1                    amd64        Modular compiler and toolchain technologies, IR interpreter
ii  llvm-10-tools                               1:10.0.0-4ubuntu1                    amd64        Modular compiler and toolchain technologies, tools
ii  protobuf-compiler                           3.6.1.3-2ubuntu5                     amd64        compiler for protocol buffer definition files
ii  sbcl                                        2:2.0.1-3                            amd64        Common Lisp compiler and development system

Is that what you meant?

find . -name libspdlog.a inside my build dir gives no results

Kind regards

ralph-lange commented 3 years ago

Could you please give the following a try: Comment out line 146 find_package(spdlog ${_spdlog_version} EXACT QUIET) in [your_micro-ROS_workspace]/src/eProsima/Micro-XRCE-DDS-Agent/cmake/SuperBuild.cmake to force a build of spdlog despite the existence of /usr/local/lib/libspdlog.a.

pablogs9 commented 3 years ago

I have successfully followed the steps in a clean Ubuntu 20.04 docker and I wasn't able to reproduce this.

https://asciinema.org/a/O0ESfgZlFoPvbdf9fiGQvkY0O

Acuadros95 commented 3 years ago

Hello @torbenf,

I have found this related issue on the spdlog repository: https://github.com/gabime/spdlog/issues/1405

Could you try modifying your build_agent.sh file (path install/micro_ros_setup/lib/micro_ros_setup/build_agent.sh) and include the mentioned CMake flag, so it looks like this:

#! /bin/bash

set -e
set -o nounset
set -o pipefail

echo "Building micro-ROS Agent"

colcon build --packages-up-to micro_ros_agent $@ --cmake-args \
    "-DCMAKE_POSITION_INDEPENDENT_CODE=ON" \
    "-DUAGENT_BUILD_EXECUTABLE=OFF" \
    "-DUAGENT_P2P_PROFILE=OFF" \
    "--no-warn-unused-cli"
torbenf commented 3 years ago

Thank you very much for all your suggestions!

@ralph-lange I tried that but got the same error. @Acuadros95 I also tried that and got the same error.

I must have messed something up before trying to install micro-ROS. A clean install will do.

@pablogs9 Thank you

I will just use the docker Image then. =)

Can be closed since it's not a micro-ROS error.

EDIT: I tried @ralph-lange suggestion again on a fresh ROS2 (from deb) and micro-ros install as i was getting he same error and it worked. I just got a detached HEAD an this output:

Finished <<< micro_ros_msgs [16.3s]                                                                          
[Processing: microxrcedds_agent]                              
[Processing: microxrcedds_agent]                                       
--- stderr: microxrcedds_agent       
Cloning into 'spdlog'...
Cloning into 'sanitizers'...
Already on 'master'
Note: switching to 'v1.4.2'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 1549ff12 Replace STRING(PREPEND ..) in CMakeLists.txt to support older CMake versions
---
Finished <<< microxrcedds_agent [1min 47s]
Starting >>> micro_ros_agent
Finished <<< micro_ros_agent [9.18s]

but the ping pong example works now. Thanks again

hhelmbold commented 2 weeks ago

Seems to me like the tutorial is outdated. Folder structures and package names have changed. After doing a colcon build, the examples are installed but definately not the same as what the tutorial suggests