🔧 1️⃣ 安装依赖
sudo apt update
sudo apt install -y autoconf automake libtool curl make g++ unzip
📥 2️⃣ 下载源码
cd ~
git clone https://github.com/protocolbuffers/protobuf.git
cd protobuf
git checkout v3.7.0
⚙️ 3️⃣ 编译 & 安装
# 生成配置脚本
./autogen.sh
# 配置编译参数(默认安装到 /usr/local)
./configure
# 编译
make -j4
# 安装
sudo make install
# 更新动态链接库
sudo ldconfig
🧪 4️⃣ 验证安装
查看版本:
protoc –version
应该会显示:
libprotoc 3.7.0
⚠️ 可能的补充
✅ 安装到指定位置 如果你想自定义安装路径:
./configure –prefix=/opt/protobuf-3.7.0
make -j4
sudo make install
然后:
export PATH=/opt/protobuf-3.7.0/bin:$PATH
sudo ldconfig
✅ 同时支持 Python 如果你需要 Python 绑定:
cd python
python3 setup.py build
python3 setup.py test
sudo python3 setup.py install
🔥 小结
1️⃣ 下载并 checkout 到 v3.7.0 2️⃣ ./autogen.sh && ./configure && make -j4 && sudo make install 3️⃣ sudo ldconfig 更新动态库
评论前必须登录!
注册