尝试将链接库“ /usr/lib/x86_64-linux-gnu/libconsole_bridge.so”添加到该目录中未构建的目标“ listener”

时间:2018-11-15 09:53:40

标签: c++ cmake ros

我遇到以下错误:

CMake Error at custom_msg/CMakeLists.txt:26 (target_link_libraries):
Attempt to add link library
"/usr/lib/x86_64-linux-gnu/libconsole_bridge.so" to target "listener" which
is not built in this directory.

CMakeList.txt

# %Tag(FULLTEXT)%
cmake_minimum_required(VERSION 2.8.3)
project(custom_msg)

## Find catkin and any catkin packages
find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs message_generation)

## Declare ROS messages and services
add_message_files(FILES Num.msg PoseVel.msg)
add_service_files(FILES AddTwoInts.srv)

## Generate added messages and services
generate_messages(DEPENDENCIES std_msgs)

## Declare a catkin package
catkin_package(CATKIN_DEPENDS message_runtime std_msgs)

## Build talker and listener
include_directories(include ${catkin_INCLUDE_DIRS})

add_executable(talker src/talker.cpp)
target_link_libraries(talker ${catkin_LIBRARIES})
add_dependencies(talker beginner_tutorials_generate_messages_cpp)

add_executable(listener src/listener.cpp)
target_link_libraries(listener ${catkin_LIBRARIES})
add_dependencies(listener beginner_turorials_generate_messages_cpp)

# %EndTag(FULLTEXT)%

我已经创建了两个包。第一个包的名称为beginner_tutorials,第二个包的名称为custom_msg。 beginner_tutorials的开发如以下链接中所述: Writing Publisher/Subscriber with C++

之后,我创建了新的custom_msg包。我复制了CMakeList.txt和源代码。我创建了一个名为PoseVel.msg的新消息,并更改了Talker.cpp中的代码。在package.xml中,我启用了message_generation和message_runtime。

我的目标是使用我自己的自定义消息。我不明白为什么新程序包会引发错误而旧程序包不会引发错误。我怎么了?

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

  

命名的目标必须由项目内的add_library()创建或作为导入库创建。如果是在项目中创建的,则会自动在构建系统中添加排序依赖项,以确保命名的库目标在链接之前是最新的。

来自here