编译grpc route_guide example的时候遇到#error This file was generated by an old version of protoc
-
原因:
- 系统中有两个protoc版本(之前下载了protobuf的git,当时编译安装了一遍。然后下grpc的git,在编译的时候按照教程使用“cmake -DgRPC_INSTALL=ON …”之后make install又安装了一遍。)
-
解决:
-
方法一:
卸载之前git 安装的protobuf:进入该目录,执行make uninstall -
方法二:
- 把route_guide example 中的Makefile的protoc版本改成protoc-3.13.0.0(也就是安装grpc的时候的protoc版本)
- 然后mount --bind /home/xxx/.local/lib/pkgconfig/protobuf.pc /usr/lib/pkgconfig/protobuf.pc(由于在生成可执行文件的时候用了pkg-config --libs protobuf, 而系统中pkg-config的 PKG_CONFIG_PATH是/usr/lib/x86_64-linux-gnu,版本号就不对,应该使用/home/xxx/.local/lib/pkgconfig/protobuf.pc)
-
-
PS:
- 为了方便直接用了mount命令,也许可以在cmake中直接加入SET(ENV{PKG_CONFIG_PATH} /home/xxx/.local/lib/pkgconfig) 或者在Makefile中加入export PKG_CONFIG_PATH :=/home/xxx/.local/lib/pkgconfig
- 有点疑问是系统中PKG_CONFIG_PATH是/usr/lib/x86_64-linux-gnu,而protobuf.pc是在/usr/lib/pkgconfig底下,这个是怎么找到的?–解决:pkg-config --variable pc_path pkg-config可以查看pkg-config的查找路径,而/usr/lib/pkgconfig包含在路径中
- 在make install的时候最好记录一下,方便后续删除(make install 2>&1 | tee makeinstall.log)