ROS中的google :: protobuf的未定义引用CPP

weixin_38060297 2019-09-12 04:00:11

我试图在ROS Indigo中使用Protocol Buffers。看起来在链接CPP源代码时存在问题。在编译时,它抛出以下错误: Linking CXX executable /home/ravi/ros_ws/devel/lib/protobuf_ros_tutorial/add_person CMakeFiles/add_person.dir/src/add_person.cc.o: In function `PromptForAddress(tutorial::Person*)': add_person.cc:(.text+0x6a): undefined reference to `google::protobuf::internal::fixed_address_empty_string' add_person.cc:(.text+0x1a5): undefined reference to `google::protobuf::internal::ArenaImpl::AllocateAlignedAndAddCleanup(unsigned long, void (*)(void*))' add_person.cc:(.text+0x1cc): undefined reference to `google::protobuf::internal::fixed_address_empty_string' add_person.cc:(.text+0x322): undefined reference to `google::protobuf::internal::fixed_address_empty_string' add_person.cc:(.text+0x454): undefined reference to `google::protobuf::util::TimeUtil::SecondsToTimestamp(long)' add_person.cc:(.text+0x496): undefined reference to `google::protobuf::Timestamp::CopyFrom(google::protobuf::Timestamp const&)' add_person.cc:(.text+0x49e): undefined reference to `google::protobuf::Timestamp::~Timestamp()' add_person.cc:(.text+0x52c): undefined reference to `google::protobuf::internal::fixed_address_empty_string' 下面是CMakeLists.txt cmake_minimum_required(VERSION 2.8.3) project(protobuf_ros_tutorial) set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}") find_package(catkin REQUIRED COMPONENTS roscpp ) find_package(Protobuf REQUIRED) catkin_package( ) include_directories( include ${catkin_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS} ) add_library(addressbook_protobuf include/addressbook.pb.cc) add_executable(add_person src/add_person.cc) target_link_libraries( add_person ${catkin_LIBRARIES} addressbook_protobuf ${PROTOBUF_LIBRARIES} ) 的package.xml是有默认内容如下: <?xml version="1.0"?> <package format="2"> <name>protobuf_ros_tutorial</name> <version>0.0.0</version> <description>The protobuf_ros_tutorial package</description> <maintainer email="[email protected]">ravi</maintainer> <license>TODO</license> <buildtool_depend>catkin</buildtool_depend> <build_depend>roscpp</build_depend> <build_export_depend>roscpp</build_export_depend> <exec_depend>roscpp</exec_depend> <export> </export> </package> 下面是ROS的文件结构包: [email protected]:~/ros_ws/src/protobuf_ros_tutorial$ ls -R .: CMakeLists.txt include package.xml src ./include: addressbook.pb.cc addressbook.pb.h addressbook.proto ./src: add_person.cc 我怀疑CMakeLists.txt文件。我错过了什么吗?






...全文
1716 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
还是喜欢阴天 2020-04-21
  • 打赏
  • 举报
回复
也可以在CMakelists.txt中强制指定protobuf3的路径
weixin_38065656 2019-09-12
  • 打赏
  • 举报
回复

Protobuf的版本不匹配。我从源码安装了Protobuf 3。但是,ROS Indigo在内部使用Protobuf 2. 作为一种解决方法,我删除了Protobuf 3,然后将其安装在我的项目本地。

433

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧