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

我试图在ROS Indigo中使用Protocol Buffers。看起来在链接CPP源代码时存在问题。在编译时,它抛出以下错误:ROS中的google :: protobuf的未定义引用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文件。我错过了什么吗?

回答:

Protobuf的版本不匹配。我从源码安装了Protobuf 3。但是,ROS Indigo在内部使用Protobuf 2.

作为一种解决方法,我删除了Protobuf 3,然后将其安装在我的项目本地。

以上是 ROS中的google :: protobuf的未定义引用CPP 的全部内容, 来源链接: utcz.com/qa/258883.html

回到顶部