JLBicho / ethercat_grant

Fork of pr2-grant to make it possible to run the ros_ethercat_loop without being root.
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

libcap-dev linking #1

Open JLBicho opened 2 years ago

JLBicho commented 2 years ago

Problem is in CMakeList.txt

If I put:

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_library(cap libcap-dev)

# message(${libCAP})

set(dependencies
  rclcpp
  cap
)

# Executables
add_executable(ethercat_grant src/ethercat_grant.cpp)
ament_target_dependencies(ethercat_grant ${dependencies})

The output of the compilation is:

colcon build
Starting >>> ethercat_grant
--- stderr: ethercat_grant                         
CMake Error at /opt/ros/foxy/share/ament_cmake_target_dependencies/cmake/ament_target_dependencies.cmake:77 (message):
  ament_target_dependencies() the passed package name 'cap' was not found
  before
Call Stack (most recent call first):
  CMakeLists.txt:34 (ament_target_dependencies)

make: *** [Makefile:266: cmake_check_build_system] Error 1
---
Failed   <<< ethercat_grant [0.41s, exited with code 2]

Summary: 0 packages finished [0.48s]
  1 package failed: ethercat_grant
  1 package had stderr output: ethercat_grant

If I put:

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_library(cap libcap-dev)

# message(${libCAP})

set(dependencies
  rclcpp
  # cap
)

# Executables
add_executable(ethercat_grant src/ethercat_grant.cpp)
ament_target_dependencies(ethercat_grant ${dependencies})

# Instala los ejecutables
install(TARGETS
  ethercat_grant
  RUNTIME DESTINATION lib/${PROJECT_NAME}
)

Then the output is:

colcon build
Starting >>> ethercat_grant
--- stderr: ethercat_grant                             
/usr/bin/ld: CMakeFiles/ethercat_grant.dir/src/ethercat_grant.cpp.o: in function `main':
ethercat_grant.cpp:(.text+0x214): undefined reference to `cap_from_text'
/usr/bin/ld: ethercat_grant.cpp:(.text+0x251): undefined reference to `cap_set_file'
/usr/bin/ld: ethercat_grant.cpp:(.text+0x2bd): undefined reference to `cap_free'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/ethercat_grant.dir/build.make:131: ethercat_grant] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/ethercat_grant.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
---
Failed   <<< ethercat_grant [0.55s, exited with code 2]

Summary: 0 packages finished [0.62s]
  1 package failed: ethercat_grant
  1 package had stderr output: ethercat_grant

So the problem is how to link the libcap-dev in the CMakeList. In ROS1 with catkin I assume it was done in the include_directories(${catkin_INCLUDE_DIRS}) step

So, if anyone has any idea it will be most welcome

JLBicho commented 2 years ago

Solved the problem with the linking of the cap library. Just had to change the ament_target_dependencies to target_link_libraries.

However, a new problem arises. With the change in capabilities, the linked libraries are lost. When running the launch file with the prefix, the libraries cannot be found.

[INFO] [mitsubishi_main-1]: process started with pid [59898]
[mitsubishi_main-1] /home/jose/ros2_ws/install/mitsubishi_servo/lib/mitsubishi_servo/mitsubishi_main: error while loading shared libraries: librcl_lifecycle.so: cannot open shared object file: No such file or directory
[ERROR] [mitsubishi_main-1]: process has died [pid 59898, exit code 127, cmd 'ethercat_grant /home/jose/ros2_ws/install/mitsubishi_servo/lib/mitsubishi_servo/mitsubishi_main --ros-args -r __ns:=/mitsubishi --params-file /home/jose/ros2_ws/install/mitsubishi_servo/share/mitsubishi_servo/params/mrj5n.yaml'].