1. Linux安装protobuf编译器
先下载protobuf-3.6.1,再执行以下操作即可
808 cd protobuf-3.6.1/
809 ./configure --prefix=/usr/local/protobuf
810 chmod 777 configure
811 ./configure --prefix=/usr/local/protobuf
816 sudo make
821 sudo make check
826 vi src/test-suite.log
827 chmod 777 src/google/protobuf/compiler/zip_output_unittest.sh
828 chmod 777 src/google/protobuf/io/gzip_stream_unittest.sh
829 sudo make check
830 sudo make install
在执行 ./configure --prefix=/usr/local/protobuf 会报权限错误,执行 chmod 777 configure 就可以解决
执行sudo make check完后又报错,报错的日志可以在src/test-suite.log查看,也是权限的问题
827 chmod 777 src/google/protobuf/compiler/zip_output_unittest.sh
828 chmod 777 src/google/protobuf/io/gzip_stream_unittest.sh
执行完之后再次执行 sudo make check
最后执行 sudo make install
查看安装本版 protoc --version
在linux中全局使用,需要配置变量
vim ~/.bashrc
最后一行添加
export PATH=/usr/local/protobuf/bin:$PATH
2. Linux安装 php protobuf扩展
克隆代码
git
clone
https:
//github.com/allegro/php-protobuf
转到源代码目录
cd ~/php-protobuf/
构建并安装PHP扩展
phpize
./configure --with-php-config=/www/server/php/72/bin/php-config
make
make install
修改php.ini配置,添加代码并重启PHP:
extension=protobuf.so
如果重启php后没有生效,查看protobuf.so路径,添加扩展的时候带上路径
extension=/www/server/php/72/lib/php/extensions/no-debug-non-zts-00000/protobuf.so
重启PHP命令
sudo systemctl restart php-fpm
3. 根据巨量提供的DMP上传数据格式文档,使用protobuf编译器生成对应的php代码
以上工作准备好后,我们将巨量提供的文档保存为 dmp_message.proto, 保存到/www/wwwroot/ss目录下
然后在ss目录下执行以下命令
protoc --php_out=. dmp_message.proto
php代码使用该代码进行数据序列化
执行的时候可能会报 \Google\Protobuf\Internal\XXX未找到,需要将对应的源文件(protobuf-3.6.1/php/src)copy到对应目录下
原文:
Linux(debian10)下安装protobuf3.6.1以及遇到的问题_make[3]: *** [google/protobuf/no_warning_test-unit-CSDN博客