我创建在C ROS2 rviz插件++,我需要编译成使用cmake共享库(.so
)。我已经有它创建了一个静态库(.a
)工作的CMakeLists.txt(见下文);我需要它来共享,虽然。
然而,当我加入SHARED
关键字到add_library
宏(在下面的代码注释掉),它抛出这个奇怪的错误:
/usr/bin/ld: cannot find -lXAW_LIBRARY-NOTFOUND
现在,我已经看了很多“的/ usr /斌/劳工处:找不到[某些库]”问题在这里SO(如this),但我的错误似乎更奇怪,因为它似乎包含一个错误(“-lXAW_LIBRARY-NOTFOUND
“)中的错误(在/ usr /斌/劳工处:找不到......)。我的意思是,为什么他甚至找了一个名为LIBRARY_NOTFOUND库?
我在Ubuntu 16.04 xenial使用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()
请注意:这个问题是不是ROS;我不是一个cmake的精灵,所以也许我只是做一些可怕的错误在cmake的......我已经问a more broad version of this question上answers.ros
,但它似乎太CMake的特定的或某事。反正,我没有得到一个答案在那里。 (上面的代码是不是MWE,对不起,我可以创建一个,如果neccessary,但它需要ROS2编译...)
一般来说,如果你是给一些库名作为参数传递给target_link_libraries
功能错误弹出。
要么,
我想看看target_link_libraries(delegator_lib rviz_common::rviz_common)
和link_directories(${ament_cmake_LIBRARY_DIRS})
为犯罪嫌疑人。
在CMake的你可以使用MESSAGE
命令做各种各样的在那里你可以显示CMake的变量的值,以检查他们是否做什么是系统上感调试。
你也可以尝试安装XAW库这样sudo apt-get install libxaw7-dev
。可能是你链接到图书馆之一对XAW库的依赖性。