undefined reference to google::protobuf in ROS CPP

匿名 (未验证) 提交于 2019-12-03 01:10:02

问题:

I am trying to use Protocol Buffers in ROS Indigo. It seems that there are problems in linking CPP source code. While compiling, it throws following errors:

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' 

Below is the 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} ) 

The package.xml is having default content as follows:

<?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="ravi@todo.todo">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> 

Below is the file structure of the ROS package:

ravi@lab:~/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 

I am doubtful about the CMakeLists.txt file. Am I missing something?

回答1:

There was a version mismatch of Protobuf. I installed Protobuf 3 from source. However, ROS Indigo internally uses Protobuf 2.

As a workaround, I removed Protobuf 3 and then installed it locally for my project.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!