一個簡單操作解決protobuf版本問題,復制粘貼你會吧


  • 這個方法雖然簡單,但是我們有完美的利用anaconda的解決方案,能夠解決服務器上大家版本沖突,你想要幾個環境就可以建立幾個完全不沖突的環境,算是一本萬利,教程在http://www.cnblogs.com/SweetBeens/p/8650460.html,推薦用這種方法。當然docker更好一些,但是老代碼是沒有docker文件的。
  • 從頭說起:

如何看你的需要安裝的版本呢,上圖:

注意看我的文件的路徑,這就是caffe官網上的那句命令行出處:

for req in $(cat requirements.txt); do pip install $req; done

鑒於我用的是segnet作者自己改的python版本的caffe,所以這是我的目錄,你可以窮搜,然后自己挑一個看看需要安裝什么。按理說照着我這個txt,不論我什么版本的都該好使,但是沒准我的txt找的不對,或者protobuf不向后兼容了,或者caffe找的anaconda的protobuf,版本有問題,總之我越來越想看有沒有caffe配置更詳細的官方原文doc,或者我應該看看linux from scrach。這種盲人摸象式解決問題損失了很多樂趣。

 

  •  我現在開始折騰我們實驗室的服務器,里面的protobuf版本比較高,所以我要用2.6.1的,我首先用下面連接的方法安裝了2.6.1:(你可以選擇跳過到最后開始解決,那是正題)

http://blog.csdn.net/whoamiyang/article/details/52947225

  • 以下是提示我的路經:
libtool: install: (cd /usr/local/lib && { ln -s -f libprotoc.so.9.0.1 libprotoc.so.9 || { rm -f libprotoc.so.9 && ln -s libprotoc.so.9.0.1 libprotoc.so.9; }; })
libtool: install: (cd /usr/local/lib && { ln -s -f libprotoc.so.9.0.1 libprotoc.so || { rm -f libprotoc.so && ln -s libprotoc.so.9.0.1 libprotoc.so; }; })
libtool: install: /usr/bin/install -c .libs/libprotoc.lai /usr/local/lib/libprotoc.la
libtool: install: /usr/bin/install -c .libs/libprotobuf-lite.a /usr/local/lib/libprotobuf-lite.a
libtool: install: chmod 644 /usr/local/lib/libprotobuf-lite.a
libtool: install: ranlib /usr/local/lib/libprotobuf-lite.a
libtool: install: /usr/bin/install -c .libs/libprotobuf.a /usr/local/lib/libprotobuf.a
libtool: install: chmod 644 /usr/local/lib/libprotobuf.a
libtool: install: ranlib /usr/local/lib/libprotobuf.a
libtool: install: /usr/bin/install -c .libs/libprotoc.a /usr/local/lib/libprotoc.a
libtool: install: chmod 644 /usr/local/lib/libprotoc.a
libtool: install: ranlib /usr/local/lib/libprotoc.a
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/sbin" ldconfig -n /usr/local/lib
----------------------------------------------------------------------
Libraries have been installed in:
/usr/local/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
/bin/mkdir -p '/usr/local/bin'
/bin/bash ../libtool --mode=install /usr/bin/install -c protoc '/usr/local/bin'
libtool: install: /usr/bin/install -c .libs/protoc /usr/local/bin/protoc
/bin/mkdir -p '/usr/local/include'
/bin/mkdir -p '/usr/local/include/google/protobuf'
/usr/bin/install -c -m 644 google/protobuf/descriptor.proto '/usr/local/include/google/protobuf'
/bin/mkdir -p '/usr/local/include/google/protobuf/compiler'
/usr/bin/install -c -m 644 google/protobuf/compiler/plugin.proto '/usr/local/include/google/protobuf/compiler'
/bin/mkdir -p '/usr/local/include'
/bin/mkdir -p '/usr/local/include/google/protobuf/compiler/cpp'

但是依舊沒有改變版本,沒有覆蓋住。

  • 以下是我的protobuf現狀:
root@test:~# whereis protoc
protoc: /usr/bin/protoc /usr/bin/X11/protoc /usr/local/bin/protoc /usr/share/man/man1/protoc.1.gz
root@test:~# pip show protobuf
Name: protobuf
Version: 3.4.1
Summary: Protocol Buffers
Home-page: https://developers.google.com/protocol-buffers/
Author: protobuf@googlegroups.com
Author-email: protobuf@googlegroups.com
License: 3-Clause BSD License
Location: /root/anaconda2/lib/python2.7/site-packages
Requires: six, setuptools
You are using pip version 9.0.1, however version 9.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
root@test:~# which protoc
/root/anaconda2/bin/protoc
root@test:~# protoc --version
libprotoc 3.4.0
root@test:~# 

 

博客一:http://blog.csdn.net/elysion122/article/details/64523339的說法只能改變使用sudo命令下的提取位置,而且我還不知道怎么編我自己的路徑。

http://blog.csdn.net/whoamiyang/article/details/52947225我的安裝來源液體到了路徑,不過我懷疑其實我都沒有安裝上,由於我的版本比較新,所以我打算用pip把它卸載了,關鍵是我怎么讓caffe聽我的話去找protobuf用

我懷疑我的caffe用的是電腦的protobuf,在我用sudo make all的時候提示我語言不通,因為我這時用的是2.5的protobuf,用的是博客一的默認路徑Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin

當我用make all的時候提示我升級版本。如果我能夠知道我的caffe上哪里找的protobuf就好了。

知乎上這個也許可用,前提是我找到了對的protobuf:

https://www.zhihu.com/question/58592005/answer/188884890

 

我用cmake出現了

incompatible with your Protocol Buffer headers.  Please update

這個錯誤

--   Release CXX flags :   -O3 -DNDEBUG -fPIC -Wall -Wno-sign-compare -Wno-uninitialized
--   Debug CXX flags   :   -g -fPIC -Wall -Wno-sign-compare -Wno-uninitialized
--   Build type        :   Release
-- 
--   BUILD_SHARED_LIBS :   ON
--   BUILD_python      :   ON
--   BUILD_matlab      :   OFF
--   BUILD_docs        :   ON
--   CPU_ONLY          :   OFF
-- 
-- Dependencies:
--   BLAS              :   Yes (Atlas)
--   Boost             :   Yes (ver. 1.54)
--   glog              :   Yes
--   gflags            :   Yes
--   protobuf          :   Yes (ver. 2.6.1)
--   lmdb              :   Yes (ver. 0.9.16)
--   Snappy            :   Yes (ver. 1.1.0)
--   LevelDB           :   Yes (ver. 1.15)
--   OpenCV            :   Yes (ver. 2.4.8)
--   CUDA              :   Yes (ver. 8.0)

以下是make all的錯誤:

CXX tools/upgrade_net_proto_text.cpp
CXX/LD -o .build_release/tools/upgrade_net_proto_text.bin
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(int, std::string const&, google::protobuf::io::CodedOutputStream*)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::io::CodedOutputStream::WriteStringWithSizeToArray(std::string const&, unsigned char*)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::AssignDescriptors(std::string const&, google::protobuf::internal::MigrationSchema const*, google::protobuf::Message const* const*, unsigned int const*, google::protobuf::MessageFactory*, google::protobuf::Metadata*, google::protobuf::EnumDescriptor const**, google::protobuf::ServiceDescriptor const**)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::Message::GetTypeName() const'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::MessageLite::SerializeToString(std::string*) const'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::MessageFactory::InternalRegisterGeneratedFile(char const*, void (*)(std::string const&))'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::Message::DebugString() const'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::OnShutdownDestroyString(std::string const*)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::WireFormatLite::WriteBytesMaybeAliased(int, std::string const&, google::protobuf::io::CodedOutputStream*)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::MessageLite::ParseFromString(std::string const&)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::NameOfEnum(google::protobuf::EnumDescriptor const*, int)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::fixed_address_empty_string'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::WireFormatLite::WriteString(int, std::string const&, google::protobuf::io::CodedOutputStream*)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::WireFormatLite::ReadBytes(google::protobuf::io::CodedInputStream*, std::string*)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::Message::InitializationErrorString() const'
collect2: error: ld returned 1 exit status
make: *** [.build_release/tools/upgrade_net_proto_text.bin] Error 1
root@test:/dev/LT/SegNet/caffe-segnet# 

 http://blog.csdn.net/xiexievv/article/details/47396725

折騰了全部的路徑也不管用。

開始解決

本教程適用於折騰半天還不管事,無奈之舉。以及不能卸載(與別人共用服務器)

中心思想,找到系統認准的protoc,用你想要的版本替換他。

你需要

1.你需要的protobuf版本

2.該版本被你安裝在哪

3.你系統認准的protobuf版本在哪

4.告訴你的系統,去哪里找lib

1安裝你需要的protobuf

這個沒什么好說的,不過提醒你最好用prefix裝在你指定的目錄,.configure --help看看怎么用prefix

 

./configure --prefix=/root/LT

 

 

 

2.找到你剛安裝的protobuf

進入他的lib文件夾:

比如我就不同尋常的裝到了LT文件夾里:不走尋常路,記住這個protoc。

 

 3.找到你系統認定的protoc在哪

終端輸入:

你也可以用命令行,找到這個protoc,給他改個名字,比如protoc_origin,然后把你想要的版本粘貼過來.這時候再輸入

 

protoc --version

 

 4.在/etc/ld.so.conf.d文件夾里面創建libprotobuf.conf

 我在LT這么一個奇葩文件夾里面安裝的,前面已經說過,所以我的lib也在這。所以我要在里面輸入/root/LT/lib

 

這時候版本就變了。由於不能卸載,所以我嘗試過各種辦法,然而都不好使。

如果你用caffe,請不要在makefile.config中用anaconda,要自己配置各種前置,不過沒准你就好使了呢。

為什么說無奈之舉呢,因為這不是作者給的。而且是身首分離的,改變不了系統認准的地址,只能替換。我試過bashrc,命令行暫時的export也試過,都不能讓系統上LT找protobuf。不走常規的方式可能有風險。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM