Why am I receiving a "cannot find" error when building ROS nodes?

I have a Simulink model with referenced models, and when I generate ROS code unfortunately the packages do not build on my Linux target when I call "catkin build". The error seems to be related to libraries not found between the nodes:
/usr/bin/ld: cannot find -lcontroller
/usr/bin/ld: cannot find -lplant
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/harness.dir/build.make:329: /home/user/username/devel/.private/harness/lib/harness/harness] Error 1
make[1]: *** [CMakeFiles/Makefile2:222: CMakeFiles/harness.dir/all] Error 2
make: *** [Makefile:144: all] Error 2
"harness" is the main model, and the referenced models are "plant" and "controller".

 Risposta accettata

There are two workarounds to this issue. The simplest is to use "catkin_make" instead of "catkin build". If you require use of "catkin build", then follow these steps:
1) In harness (Top-model) "CMakeLists.txt", remove the dependent libraries (plant and controller) from "target_link_libraries", i.e., change 
 
target_link_libraries(  harness 
    controller
    plant
    ${catkin_LIBRARIES}
    ${Boost_LIBRARIES}
    ${CMAKE_DL_LIBS}
)
 to
target_link_libraries(  harness 
    ${catkin_LIBRARIES}
    ${Boost_LIBRARIES}
    ${CMAKE_DL_LIBS}
)
2) In plant (Ref-model) "CMakeLists.txt", add the "LIBRARIES" section in "catkin_package", i.e., change 
catkin_package(
  CATKIN_DEPENDS
  ackermann_msgs
  nav_msgs
  roscpp
  sensor_msgs
  std_msgs
  INCLUDE_DIRS include
)
to
catkin_package(
  LIBRARIES plant
  CATKIN_DEPENDS
  ackermann_msgs
  nav_msgs
  roscpp
  sensor_msgs
  std_msgs
  INCLUDE_DIRS include
)
3) In controller (Ref-model) "CMakeLists.txt", add the "LIBRARIES" section in "catkin_package", i.e., change 
catkin_package(
  CATKIN_DEPENDS
  roscpp
  std_msgs
  INCLUDE_DIRS include
)
to
catkin_package(
  LIBRARIES controller
  CATKIN_DEPENDS
  roscpp
  std_msgs
  INCLUDE_DIRS include
)
 
Executing "catkin build" should work fine after taking these steps.

Più risposte (0)

Prodotti

Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by