Search code examples
c++cmakeshared-librariesld

What does this strange "/usr/bin/ld: cannot find -lXAW_LIBRARY-NOTFOUND" error mean?


I created a ROS2 rviz plugin in C++ which I need to compile into a shared library (.so) using cmake. I already have a working CMakeLists.txt (see below) which creates a static library (.a); I need it to be shared, though.

However, when I add the SHARED keyword to the add_library macro (commented out in the code below), it throws this strange error:

/usr/bin/ld: cannot find -lXAW_LIBRARY-NOTFOUND

Now, I have looked at the many "/usr/bin/ld: cannot find [some library]" questions here on SO (like this), but my error seems to be more strange since it seems to contain an error ("-lXAW_LIBRARY-NOTFOUND") IN THE error (/usr/bin/ld: cannot find...). I mean, why is he even looking for a library called LIBRARY_NOTFOUND??

I'm on Ubuntu xenial 16.04 using cmake 3.10.

CMakeLists.txt:

project(traffic_sign_delegation_manager)

set(CMAKE_CXX_STANDARD 17)

if(NOT WIN32)
  add_definitions(-fPIC)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic -Wno-deprecated-declarations)
endif()

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)

find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rviz_common REQUIRED)
find_package(std_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(rosidl_generator_cpp)
find_package(pluginlib REQUIRED)

find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5OpenGL REQUIRED)
find_package(Qt5 REQUIRED COMPONENTS Widgets)

set(msg_files
  "msg/TrafficSignList.msg"
  "msg/TrafficSign.msg"
  "msg/TrafficSignSetList.msg"
  "msg/TrafficSignSet.msg"
  "msg/TrafficSignSetStatus.msg"
  "msg/TrafficSignsManaged.msg"
  "msg/AccLever2.msg"
  "msg/VehicleOdometry.msg"
)

rosidl_generate_interfaces(${PROJECT_NAME}
  ${msg_files}
  DEPENDENCIES std_msgs
)

link_directories(${ament_cmake_LIBRARY_DIRS})

add_definitions(-DQT_NO_KEYWORDS)

qt5_wrap_ui(QT_UI_FILES ui/traffic_sign_delegation_manager_panel.ui)
qt5_wrap_ui(QT_UI_FILES ui/traffic_sign_list_item.ui)

qt5_add_resources(QT_QRC_FILES ui/traffic_sign_delegation_manager.qrc)

set_property(SOURCE traffic_sign_delegation_manager_panel.h PROPERTY SKIP_AUTOMOC ON)
set_property(SOURCE draw_area.h PROPERTY SKIP_AUTOMOC ON)
set_property(SOURCE adv_interaction_groupbox.h PROPERTY SKIP_AUTOMOC ON)
set_property(SOURCE traffic_sign_delegation_manager_display.h PROPERTY SKIP_AUTOMOC ON)

add_library(delegator_lib   # SHARED # <=== WHY IS THIS NOT WORKING?
  vec2d.cpp
  vec2d.h
  traffic_sign_delegation_manager_panel.cpp
  traffic_sign_delegation_manager_panel.h
  draw_area.cpp
  draw_area.h
  traffic_sign_delegation_manager_display.cpp
  traffic_sign_delegation_manager_display.h
  adv_interaction_groupbox.cpp
  adv_interaction_groupbox.h
  ui/traffic_sign_list_item.ui
  ui/traffic_sign_delegation_manager_panel.ui
  ${QT_UI_FILES}
  ${MOC_FILES}
)

rosidl_target_interfaces(delegator_lib ${PROJECT_NAME} "rosidl_typesupport_cpp")

target_include_directories(delegator_lib PUBLIC
  ${rvizCommon_DIR}
  ${rosidl_generator_cpp_INCLUDE_DIRS}
  ${ament_cmake_INCLUDE_DIRS}
  ${rviz2_INCLUDE_DIRS}
  ${rviz_common_INCLUDE_DIRS}
  ${FREETYPE_INCLUDE_DIRS}
  ${Qt5_INCLUDE_DIRS}
)

target_link_libraries(delegator_lib
  rviz_common::rviz_common
)

target_compile_definitions(delegator_lib PRIVATE "RVIZ_DEFAULT_PLUGINS_BUILDING_LIBRARY")
target_compile_definitions(delegator_lib PUBLIC "PLUGINLIB__DISABLE_BOOST_FUNCTIONS")

pluginlib_export_plugin_description_file(rviz_common plugin_description.xml)

ament_target_dependencies(delegator_lib
  geometry_msgs
  laser_geometry
  nav_msgs
  map_msgs
  rclcpp
  resource_retriever
  urdf
  visualization_msgs
)

ament_export_include_directories(${INCLUDE_DIRS} ${ament_cmake_INCLUDE_DIRS} include)
ament_export_interfaces(delegator_lib HAS_LIBRARY_TARGET)

ament_export_dependencies(
  Qt5
  rviz_common
  geometry_msgs
  laser_geometry
  map_msgs
  nav_msgs
  rclcpp
  urdf
  visualization_msgs
  rosidl_generator_cpp
)

install(FILES plugin_description.xml
  DESTINATION share/${PROJECT_NAME})
install(DIRECTORY images
  DESTINATION share/${PROJECT_NAME})
install(DIRECTORY ui
  DESTINATION share/${PROJECT_NAME}
  PATTERN "*.ui"
  EXCLUDE)

install(
  TARGETS delegator_lib
  EXPORT delegator_lib
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION bin
  INCLUDES DESTINATION include
)

install(
  DIRECTORY "${CMAKE_SOURCE_DIR}/icons"
  DESTINATION "share/${PROJECT_NAME}"
)

ament_package()

Please note: This question is not about ROS; I am not a cmake wizard, so probably I'm just doing something terribly wrong in cmake... I already asked a more broad version of this question on answers.ros, but it appears to be too cmake-specific or something. Anyway, I did not get an answer there. (The above code is not an MWE, sorry; I could create one if neccessary, but it would require ROS2 to compile...)


Solution

  • Normally that error pops up if you are giving some library names as arguments to the target_link_libraries function.

    Either,

    1. The names are not correct or,
    2. The path is not or,
    3. The libraries are not installed.

    I'd look at target_link_libraries(delegator_lib rviz_common::rviz_common) and link_directories(${ament_cmake_LIBRARY_DIRS}) as suspects.

    In CMake you can use MESSAGE command to do debugging of sorts where you can display the values of the CMake variables to check if they make sense with what is on the system.

    Also you can try installing the XAW library like this sudo apt-get install libxaw7-dev. Could be that one of the libraries that you link to has a dependency on the XAW library.