这个奇怪的“ / usr / bin / ld:找不到-lXAW_LIBRARY-NOTFOUND”错误是什么意思?

时间:2019-02-05 10:12:55

标签: c++ cmake shared-libraries ld

我用C ++创建了一个ROS2 rviz插件,我需要使用cmake将其编译为共享库(.so)。我已经有一个正常工作的CMakeLists.txt(请参见下文),它创建了一个 static 库(.a);不过,我需要将其共享。

但是,当我将SHARED关键字添加到add_library宏时(在下面的代码中进行了注释),它引发了这个奇怪的错误:

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

现在,我在SO上查看了很多“ / usr / bin / ld:找不到 [某些库] ”问题(例如this),但是我的错误似乎更加奇怪,因为它似乎在错误中包含错误(“ -lXAW_LIBRARY-NOTFOUND”)(/ usr / bin / ld:找不到...)。我的意思是,他为什么还要寻找一个名为LIBRARY_NOTFOUND的库?

我在使用cmake 3.10的Ubuntu xenial 16.04。

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()

请注意:此问题与ROS有关;我不是cmake向导,所以可能我在cmake中做的是一个非常错误的事情……我已经在answers.ros上问过a more broad version of this question,但是它似乎太特定于cmake了。无论如何,我在那里没有得到答案。 (抱歉,上面的代码不是MWE,我可以根据需要创建一个,但是需要ROS2进行编译...)

1 个答案:

答案 0 :(得分:1)

通常,如果您将某些库名用作target_link_libraries函数的参数,则会弹出该错误。

要么

  1. 名称不正确,或者
  2. 路径不是or
  3. 未安装库。

我会把target_link_libraries(delegator_lib rviz_common::rviz_common)link_directories(${ament_cmake_LIBRARY_DIRS})看成是犯罪嫌疑人。

CMake 中,您可以使用MESSAGE命令进行各种调试,在其中可以显示CMake变量的值,以检查它们对系统中的内容是否有意义。 / p>

您还可以尝试安装sudo apt-get install libxaw7-dev这样的 XAW 库。可能是您链接到的库之一依赖于XAW库。