protobuf Linux编译Protocol Buffers v3.0.0
原创
©著作权归作者所有:来自51CTO博客作者fengyuzaitu的原创作品,请联系作者获取转载授权,否则将追究法律责任
前言
编译代码提示出错:
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
说明protobuf生成的头文件版本跟系统目前安装的版本不一致,通过打开生成头文件,查看到GOOGLE_PROTOBUF_VERSION < 3000000,说明依赖版本3.0.0
源码下载
wget https://github.com/protocolbuffers/protobuf/archive/refs/tags/v3.0.0.tar.gz
源码编译
编译依赖指令工具有 libtool perl automake m4 autotools-dev autoconf
执行下面命令之前,确保都已经安装完毕
yum install libtool perl automake m4 autotools-dev autoconf
./autogen.sh
./configure
make
make install
编译问题解决
Google Mock not present. Fetching gmock-1.7.0 from the web..
打开文件autogen.sh文件
30 # Check that gmock is present. Usually it is already there since the
31 # directory is set up as an SVN external.
32 if test ! -e gmock; then
33 echo "Google Mock not present. Fetching gmock-1.7.0 from the web..."
34 curl $curlopts -O https://googlemock.googlecode.com/files/gmock-1.7.0.zip
35 unzip -q gmock-1.7.0.zip
36 rm gmock-1.7.0.zip
37 mv gmock-1.7.0 gmock
38 fi
删除这一段脚本,然后执行如下指令
curl $curlopts -L -O https://github.com/google/googletest/archive/release-1.7.0.zip
unzip -q release-1.7.0.zip
rm release-1.7.0.zip
mkdir gmock/
mv googletest-release-1.7.0 gmock/gtest
原理,手动下载依赖的测试安装包,下载如果出现异常,可以直接下载
Can‘t exec “aclocal“:
没有那个文件或目录 at /usr/share/autoconf/Autom4te/FileUtils.pm line 326
缺少libtool
autoreconf: not found”
缺少automake autoconf
Can't locate Thread/Queue.pm in @INC
缺少perl-Thread-Queue
Can’t locate Data/Dumper.pm in @INC
缺少perl
对‘google::protobuf::internal::empty_string_’未定义的引用
/usr/local/include/google/protobuf/stubs/once.h:128:对‘google::protobuf::GoogleOnceInitImpl(long*, google::protobuf::Closure*)’未定义的引用
kafka/deepdata.pb.o:在函数‘google::protobuf::internal::GetEmptyStringAlreadyInited()’中:
/usr/local/include/google/protobuf/generated_message_util.h:86:对‘google::protobuf::internal::empty_string_’未定义的引用
kafka/deepdata.pb.o:在函数‘dg::model::GenericObj::MergeFrom(dg::model::GenericObj const&)’中:
/opt/expresswayAccess/kafka/deepdata.pb.cpp:397:对‘google::protobuf::internal::ArenaStringPtr::AssignWithDefault(std::string const*, google::protobuf::internal::ArenaStringPtr)’未定义的引用
kafka/deepdata.pb.o:在函数‘void google::protobuf::Arena::OwnInternal<dg::model::GenericObj>(dg::model::GenericObj*, google::protobuf::internal::integral_constant<bool, true>)’中:
/usr/local/include/google/protobuf/arena.h:824:对‘google::protobuf::Arena::AddListNode(void*, void (*)(void*))’未定义的引用
kafka/deepdata.pb.o:(.rodata._ZTVN2dg5model10GenericObjE[_ZTVN2dg5model10GenericObjE]+0x90):对‘google::protobuf::MessageLite::InternalSerializeWithCachedSizesToArray(bool, unsigned char*) const’未定义的引用
kafka/deepdata.pb.o:(.rodata._ZTVN2dg5model10GenericObjE[_ZTVN2dg5model10GenericObjE]+0xb0):对‘google::protobuf::Message::SpaceUsed() const’未定义的引用
radarcommunications.o:在函数‘google::protobuf::internal::GetEmptyStringAlreadyInited()’中:
/usr/local/include/google/protobuf/generated_message_util.h:86:对‘google::protobuf::internal::empty_string_’未定义的引用
/usr/local/include/google/protobuf/generated_message_util.h:86:对‘google::protobuf::internal::empty_string_’未定义的引用
指定动态库的绝对路径:/usr/local/lib/libprotobuf.so
error: possibly undefined macro: AC_PROG_LIBTOOL
将/usr/share/aclocal/下的*.m4文件都拷贝到usr/local/share/aclocal/目录下