操作系统

[root@localhost librdkafka-master]# cat /etc/redhat-release  

CentOS Linux release 7.7.1908 (Core)


前言

直接安装方式

yum install protobuf-lite-devel.x86_64

由于librdkafka依赖高版本的protobuf,因此源码编译


configure方式源码编译安装

git clone https://github.com/google/protobuf.git

cd protobuf

这个是下载第三方关联库,非常重要

git submodule update --init --recursive

(执行以后,在第三方库多了Abseil - C++ Common Libraries)

[root@localhost protobuf]# mkdir build  

[root@localhost protobuf]# cd build

[root@localhost build]# cmake -DCMAKE_INSTALL_PREFIX="/opt/proto3.17"  -Dprotobuf_BUILD_TESTS=OFF   -DBUILD_SHARED_LIBS=ON    ../

make

make install

备注

也可以参考​​https://blog.51cto.com/fengyuzaitu/5638178​​编译方式

问题

1 absl::algorithm

CMake Error at cmake/protoc.cmake:6 (target_link_libraries):

  Target "protoc" links to:

  absl::algorithm

  but the target was not found.  Possible reasons include:

git submodule update --init --recursive这一步,主要是下载依赖的第三方库

2 absl这个库依赖C++14,所以需要升级编译器

3Cannot find third_party/googletest directory that's needed to build tests

CMake Error at tests.cmake:2 (message):

 Cannot find third_party/googletest directory that's needed to build tests.

 If you use git, make sure you have cloned submodules:


   git submodule update --init --recursive


 If instead you want to skip tests, run cmake with:


   cmake -Dprotobuf_BUILD_TESTS=OFF


Call Stack (most recent call first):

 CMakeLists.txt:282 (include)

解决方案:

配置选项添加 -Dprotobuf_BUILD_TESTS=OFF

4编译动态库

配置选项添加 -DBUILD_SHARED_LIBS=ON