Ubuntu16.04安裝protobuf(最靠譜的)

emmmmmmm..... Ubuntu16.04自帶protobuf

protoc --version 查看版本

whereis protoc 查看安裝位置

which protoc 如果有多個protobuf,查看默認使用的protobuf

 

方法一:

1、下載google protocol buffers,下載地址:http://code.google.com/p/protobuf/,解壓到了/usr/local下

 

2、./configue,不出意外如下:

cd protobuf-master./configue

but:

看網上所有的教程都是直接進入protobuf主目錄,並且./configue,但是我運行時一直提示沒有./configue文件

安裝aotomake,先用automaker生成configure文件:

apt-get install automake./autogen.sh./configure

然後坑爹的是,我在運行autogen.sh時,報了下面的錯:

+ mkdir -p third_party/googletest/m4+ autoreconf -f -i -Wall,no-obsoleteconfigure.ac:104: error: possibly undefined macro: AC_PROG_LIBTOOL      If this token and others are legitimate, please use m4_pattern_allow.      See the Autoconf documentation.autoreconf: /usr/bin/autoconf failed with exit status: 1

大意是找不到libtool解決:

apt-get install libtool

 

3、make:

makemake checkmake install

然後 make check的時候,報了一個亂七八糟的錯誤,好不容易解決了,又報了另一個錯,後來師兄告訴我,protobuf安裝時make check出錯可以先不用管,暫時跳過,後期出錯了再回來排查就好了。

 

4、檢查是否安裝成功

protoc --version

安裝成功會顯示版本信息,安裝失敗會提示錯誤信息,不出意外,又報錯了。。。。。。錯誤信息:

protoc —versionprotoc: error while loading shared libraries: libprotoc.so.17: cannot open shared object file: No such file or directory

這是Ubuntu安裝protobuf常見的一種問題,原因是:protobuf的默認安裝路徑是/usr/local/lib,而/usr/local/lib 不在Ubuntu體系默認的 LD_LIBRARY_PATH 裏,所以就找不到該lib[2]。解決方法,在/usr/lib下創建protocol buffer相關庫的軟鏈接:

cd /usr/libln -s /usr/local/lib/libprotobuf.so.17 libprotobuf.so.17ln -s /usr/local/lib/libprotoc.so.17 libprotoc.so.17

至此,protobuf安裝成功,但是想要在python中使用,還要編譯python接口

 

5、編譯protobuf的python接口

cd python python setup.py build python setup.py test python setup.py install

在python中測試一下,如果import google.protobuf沒有報錯就可以用啦。

 

方法二:

pip or apt

 

 

我的媽耶,環境問題對小白真的一點一點都不友好,各種報錯。。。爲什麼大佬們配環境可以這麼順利,羨慕大佬 😍😍😍

 

 

 

 

參考鏈接:

【1】Ubuntu 16.04 安裝 protobuf 以及測試/使用:https://blog.csdn.net/qq_16775293/article/details/81119375(包含protobuf的安裝和覆蓋安裝流程)

【2】protocol buffer安裝後使用出錯:https://blog.csdn.net/keheinash/article/details/51063332(protoc --version出錯的兩種解決方法)
---------------------
作者:王小白的博客
來源:CSDN
原文:https://blog.csdn.net/sunshine__0411/article/details/84251773
版權聲明:本文爲博主原創文章,轉載請附上博文鏈接!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章