grpc-c编译

  关于grpc-c的示例代码地址 https://github.com/lixiangyun/grpc-c.git ,该项目采用gRPC v1.17.2 .

故障排查罗列

本文采用CentOS系统,其中grpc-c趟坑过程记录如下

  1. 安装依赖项
#ubuntu系统
apt install -y autoconf automake libtool curl make cmake g++ unzip zlib1g-dev \
zlib1g openssl libssl-dev pkg-config libgflags-dev libgtest-dev

#centos系统
yum install -y autoconf automake libtool curl make cmake  unzip  openssl gcc-c++ \
openssl-devel gflags-devel gtest gtest-devel zlib-devel zlib
#pcre-devel zlib zlib-devel openssl openssl-devel

#如果独立安装protobuf,该官方提供的版本为2.5.0。在该项目不使用
#yum install -y protobuf protobuf-devel
  1. 找不到库openssl 或zlib

No package 'zlib' found
Package openssl was not found in the pkg-config search path.
Perhaps you should add the directory containing openssl.pc' to the PKG_CONFIG_PATH environment variable No package 'openssl' found Package openssl was not found in the pkg-config search path. Perhaps you should add the directory containingopenssl.pc'
to the PKG_CONFIG_PATH environment variable
No package 'openssl' found
Package openssl was not found in the pkg-config search path.
Perhaps you should add the directory containing openssl.pc' to the PKG_CONFIG_PATH environment variable No package 'openssl' found Package zlib was not found in the pkg-config search path. Perhaps you should add the directory containingzlib.pc'
to the PKG_CONFIG_PATH environment variable
No package 'zlib' foun

find / -name openssl.pc
find / -name zlib.pc
#export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:/usr/lib64/pkgconfig

#PKG_CONFIG_PATH路径需要配置为包含文件libprotobuf-c.pc的绝对路径
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:$PKG_CONFIG_PATH

#export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:/usr/lib64/pkgconfig:$PKG_CONFIG_PATH
  1. 找不到XXX.so
#报错如下
protoc: error while loading shared libraries: libprotobuf.so.17: cannot open shared object file: No such file or directory
#解决方法
//找不到XXX.so, 通过find命令找到文件位置,并加入ld索引目录中
echo "/usr/local/lib" >> /etc/ld.so.conf
#echo "/usr/local/lib64" >> /etc/ld.so.conf
ldconfig
  1. 重新编译如果无法找到文件

//zconf.h missing when building with make
make clean

  1. 编译测试文件时链接错误

//usr/local/lib/libgrpc-c.so:对‘grpc_call_unref’未定义的引用
collect2: 错误:ld 返回 1
make[2]: [foo/foo_bin] 错误 1
make[1]:
[foo/CMakeFiles/foo_bin.dir/all] 错误 2
make: [all] 错误 2
[ 16%] Linking C executable foo_bin
//usr/local/lib/libgrpc-c.so:对‘grpc_call_unref’未定义的引用
collect2: 错误:ld 返回 1
make[2]:
[foo/foo_bin] 错误 1
make[1]: [foo/CMakeFiles/foo_bin.dir/all] 错误 2
make:
[all] 错误 2

  搜索该文件,grpc已经在另一个位置安装有,即/usr/lib以及/usr/local/lib都有该动态链接库,以及相应的.h文件在以上两个目录的include目录中,删除重复的。重新编译,即可解决问题。

Build

git clone https://github.com/lixiangyun/grpc-c.git
cd grpc-c
./builddeps.sh
./buildlib.sh
./buildcmp.sh

If you want to install dependencies in a different directory other than /usr/local/, use ./builddeps.sh and ./buildlib.sh

Examples

cd examples
./build.sh

To run example code:

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
cd examples
./bin/foo_bin server
./bin/foo_bin client

Package

安装python版本
cd /python
python setup.py build
python setup.py install 安装完成

发表评论

邮箱地址不会被公开。 必填项已用*标注