Redhat 系统上安装 Protobuf

本文档记录了在远程服务器 Tesla K80 Redhat 系统上安装 Protobuf 的过程

我从这里 下了 protobuf-3.2.0.tar.gz。

# tar zxvf protobuf-3.2.0.tar.tgz
# cd protobuf-3.2.0/
# ./configure
checking whether to enable maintainer-specific portions of Makefiles... yes
checking build system type... x86_64-unknown-linux-gnu
......................
configure: creating ./config.status
config.status: creating Makefile
config.status: creating scripts/gtest-config
config.status: creating build-aux/config.h
config.status: executing depfiles commands
config.status: executing libtool commands
# make
make all-recursive
......................
make[2]: ***[google/protobuf/any.pb.lo] Error 1
make[2]: Leaving directory '/root/K80/protobuf-3.2.0/src'
make[1]: ***[all-recursive] Error 1
make[1]: Leaving directory '/root/K80/protobuf-3.2.0'
make: *** [all] Error 2

上网查了一下,有人说用 autogen.sh 先跑一下:

# ./autogen.sh
./autogen.sh: line 48: autoreconf: command not found

发现 autoreconf 没有安装,安装 autoreconf,automake 和 libtool 三个包:

Step 1 安装 autoreconf,从这里下载

# tar zxvf autoconf-2.69.tar.gz
# cd autoconf-2.69/
# ./configure
# make
# make install

检测你的 autoconf 成功安装:

# autoconf --version
autoconf (GNU Autoconf) 2.69
...
...
...

Step 2 安装 automake,从这里下载

# tar zxvf automake-1.14.tar.gz
# cd automake-1.14/
# ./configure
# make
# make install

查看你的 automake 路径及版本:

# which auautomake
/usr/local/bin/automake
# automake --version
automake (GNU automake) 1.14

Step 3 安装 libtool,从这里下载

# tar -xzf libtool-2.4.2.tar.gz
# cd libtool-2.4.2
# ./configure
# make
# make install
# make check

再次运行 autogen.sh:

# ./autogen.sh
# ./configure --prefix=/usr/local/protobuf
# make
'google::protobuf::internal::InternalMetadataWithArena::InternalMetadataWithArena(google::protobuf::Arena*)':
./google/protobuf/metadata.h:175: error: class 'google::protobuf::internal::InternalMetadataWithArena' does not have any field named 'InternalMetadataWithArenaBase'
./google/protobuf/metadata.h: In constructor 'google::protobuf::internal::InternalMetadataWithArenaLite::InternalMetadataWithArenaLite(google::protobuf::Arena*)':
./google/protobuf/metadata.h:204: error: class 'google::protobuf::internal::InternalMetadataWithArenaLite' does not have any field named 'InternalMetadataWithArenaBase'
make[2]: *** [google/protobuf/any.pb.lo] Error 1
make[2]: Leaving directory /home/protobuf/src' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory/home/protobuf'
make: *** [all] Error 2

以上错误为 google 的一个 bug,已经在 #2559 修复,但是可能在 release 中还没有更改,所以手动更改一下:

# cd /src/google/protobuf/
# vim metadata.h

向 metadata.h 中进行如下更改:

 public:
    InternalMetadataWithArena() {}
    explicit InternalMetadataWithArena(Arena* arena)
 -      : InternalMetadataWithArenaBase(arena) {}
 +      : InternalMetadataWithArenaBase(arena) {}

    void DoSwap(UnknownFieldSet* other) {
      mutable_unknown_fields()->Swap(other);
 @@ -201,7 +202,8 @@ class InternalMetadataWithArenaLite
    InternalMetadataWithArenaLite() {}

    explicit InternalMetadataWithArenaLite(Arena* arena)
 -      : InternalMetadataWithArenaBase(arena) {}
 +      : InternalMetadataWithArenaBase(arena) {}

    void DoSwap(string* other) {
      mutable_unknown_fields()->swap(*other);

再次 make:

# make
# make install

你可能感兴趣的:(Linux)