无法在ROS中使用本地安装的协议缓冲区 [英] Unable to use locally installed Protocol Buffers inside ROS
问题描述
我已经在本地安装了协议缓冲区.下面是ROS包的目录结构:
I have installed Protocol Buffers locally. Below is the directory structure of ROS package:
.
├── CMakeLists.txt
├── package.xml
├── include
│ ├── addressbook.pb.cc
│ ├── addressbook.pb.h
│ └── addressbook.proto
├── lib
│ └── protobuf-3.5.0
└── src
└── main.cpp
协议缓冲区是使用在本地安装的./configure--prefix= $ PWD
在 lib/protobuf-3.5.0
目录中.
虽然使用 catkin_make
编译ROS软件包,但似乎是指协议缓冲区的旧安装并显示版本不兼容错误.
While compiling the ROS package using catkin_make
, it seems referring to an old installation of Protocol Buffers and showing version incompatibility errors.
[ 0%] Building CXX object local_protobuf_ros_example/CMakeFiles/addressbook_protobuf.dir/include/addressbook.pb.cc.o
In file included from /home/bgplvm/ros_ws/src/local_protobuf_ros_example/include/addressbook.pb.cc:4:0:
/home/bgplvm/ros_ws/src/local_protobuf_ros_example/include/addressbook.pb.h:12:2: error: #error This file was generated by a newer version of protoc which is
#error This file was generated by a newer version of protoc which is
^
/home/bgplvm/ros_ws/src/local_protobuf_ros_example/include/addressbook.pb.h:13:2: error: #error incompatible with your Protocol Buffer headers. Please update
#error incompatible with your Protocol Buffer headers. Please update
^
/home/bgplvm/ros_ws/src/local_protobuf_ros_example/include/addressbook.pb.h:14:2: error: #error your headers.
#error your headers.
^
In file included from /home/bgplvm/ros_ws/src/local_protobuf_ros_example/include/addressbook.pb.cc:4:0:
/home/bgplvm/ros_ws/src/local_protobuf_ros_example/include/addressbook.pb.h:23:35: fatal error: google/protobuf/arena.h: No such file or directory
#include <google/protobuf/arena.h>
^
compilation terminated.
尽管如此,我在 CMakeLists.txt
内放入了 message(STATUS使用协议缓冲区$ {Protobuf_VERSION}")
语句,发现它正在使用协议缓冲区3.5.0.参见下面的 CMakeLists.txt
:
Although, I put message(STATUS "Using Protocol Buffers ${Protobuf_VERSION}")
statement inside CMakeLists.txt
and found that it is using Protocol Buffers 3.5.0. See below the CMakeLists.txt
:
cmake_minimum_required(VERSION 2.8.3)
project(local_protobuf_ros_example)
find_package(catkin REQUIRED COMPONENTS roscpp)
set(PROTOBUF_FOLDER ${PROJECT_SOURCE_DIR}/lib/protobuf-3.5.0)
set(CMAKE_PREFIX_PATH
${CMAKE_PREFIX_PATH}
"${PROTOBUF_FOLDER}/cmake/build/release/lib/x86_64-linux-gnu/cmake/protobuf"
)
find_package(Protobuf CONFIG REQUIRED)
message(STATUS "Using Protocol Buffers ${Protobuf_VERSION}")
catkin_package()
include_directories(include ${catkin_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS})
add_library(addressbook_protobuf include/addressbook.pb.cc)
add_executable(main src/main.cpp)
target_link_libraries(main ${catkin_LIBRARIES} addressbook_protobuf ${PROTOBUF_LIBRARIES})
这里缺少什么?由于我指的是本地安装,因此它应该可以正常工作而不会显示错误.不是吗?
What is missing here? Since I am referring to the local installation, it should work without showing errors. Isn't it?
推荐答案
您的 CMAKE_PREFIX_PATH
集不正确.它应该指向安装protobuf的前缀,而不是指向该软件包的cmake配置文件的位置.
Your set of CMAKE_PREFIX_PATH
is incorrect. It should point to the prefix in which protobuf was installed, not the location of the cmake config file for the package.
所以尝试更改:
set(CMAKE_PREFIX_PATH
${CMAKE_PREFIX_PATH}
${PROTOBUF_FOLDER}/cmake/build/release/lib/x86_64-linux-gnu/cmake/protobuf
)
对此:
set(CMAKE_PREFIX_PATH
${CMAKE_PREFIX_PATH}
${PROTOBUF_FOLDER}
)
也就是说,假设 $ {PROTOBUF_FOLDER}
指向赋予的--prefix参数的相同位置./configure--prefix =< INSTALL_PREFIX>
That is, assuming ${PROTOBUF_FOLDER}
points to the same location given to the --prefix argument of ./configure --prefix=<INSTALL_PREFIX>
请参阅 find_package
的搜索路径文档在这里.(大约在页面的一半)
See the search paths documentation for find_package
here. (about half way down the page)
我相信,如果您使用的是Windows,那么原本作为< prefix>/
的工作就是该平台的搜索路径之一.但是在基于Unix的OS上,您将这些作为搜索路径(根据上面链接中的文档):
I believe if you were on Windows what you had would have worked as <prefix>/
is one of the search paths for that platform. But on Unix based OS'es you have these as the search paths (per the documentation on above link):
<prefix>/(lib/<arch>|lib|share)/cmake/<name>*/
<prefix>/(lib/<arch>|lib|share)/<name>*/
<prefix>/(lib/<arch>|lib|share)/<name>*/(cmake|CMake)/
在这里,您还必须注意区分大小写.请注意,在上述路径中,他们搜索的最后一个路径元素是< name> *
.从您的问题中我可以看到,protobuf似乎以以下名称安装自己:'protobuf',但您的 find_package
调用要求输入'Protobuf'.因此,请尝试将您的通话也更改为:
You also have to be careful about case sensitivity here. Note that in the above paths the last path element they search is <name>*
. From what I can see in your question it looks like protobuf installs itself under the name of
'protobuf', but your find_package
call is asking for 'Protobuf'. So, try also changing your call to:
find_package(protobuf CONFIG REQUIRED)
最后,据我所知,protobuf在通过 ./configure ...
进行构建时未安装CMake配置.要安装CMake配置,我必须通过CMake进行以下操作:
And finally, as far as I can tell, protobuf doesn't install CMake configs when doing a build via ./configure ...
. To get the CMake configs installed I had to build via CMake by doing:
cd protobuf-3.5/cmake
cmake -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> .
make
make install
这篇关于无法在ROS中使用本地安装的协议缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!