proto/caffe.pb.h:17:2: error: #error This file was generated by an older version of protoc

根據<<深度學習21天實戰Caffe>>書中P102頁,編寫程序 blob_demo.cpp, 並把它放置在caffe目錄下,
編譯時出現如下提示:

sf@ubuntu:~/caffe$ g++ -o app ./blob_demo.cpp -I ./include/ -D CPU_ONLY -I ./.build_release/src -L .ildb/ -lcaffe
In file included from ./include/caffe/blob.hpp:9:0,
                 from ./blob_demo.cpp:3:
./.build_release/src/caffe/proto/caffe.pb.h:17:2: error: #error This file was generated by an older version of protoc which is
 #error This file was generated by an older version of protoc which is
  ^
./.build_release/src/caffe/proto/caffe.pb.h:18:2: error: #error incompatible with your Protocol Buffer headers. Please
 #error incompatible with your Protocol Buffer headers.  Please
  ^
./.build_release/src/caffe/proto/caffe.pb.h:19:2: error: #error regenerate this file with a newer version of protoc.
 #error regenerate this file with a newer version of protoc.
  ^
In file included from ./include/caffe/blob.hpp:9:0,
                 from ./bd.cpp:3:
./.build_release/src/caffe/proto/caffe.pb.h: In member function ‘void caffe::Datum::clear_data()’:
./.build_release/src/caffe/proto/caffe.pb.h:10766:17: error: ‘kEmptyString’ is not a member of ‘google::protobuf::internal’
   if (data_ != &::google::protobuf::internal::kEmptyString) {


                 ^
省略很多類似出錯提示


 根據
/.build_release/src/caffe/proto/caffe.pb.h:17:2: error: #error This file was generated by an older version of protoc which is
 #error This file was generated by an older version of protoc which is

是否 因爲作者百度網盤上下的工具包 與現在從git上下載的caffe源程序不兼容?

後來查資料,參考如下:

Hi guys,
It seems this issue has been wrongly closed while some guys haven't managed to solve the problems with protobuf, protoc, .. So I would like to open this issue and give a thorough solution which would solve most of the problems regarding protobuf during caffe installation;
Here the solution goes:

Make sure you don't have already install protobuf and other similar name files
$ sudo apt-get clean
$ sudo apt-get autoclea
$ sudo apt-get autoremove
$ sudo apt-get remove --purge proto\tab              % remove all the files by pressing tab and finding those file or using *.   注:按tab鍵,補齊:protobuf-compiler
$ sudo dpkg -P proto\tab                                     注:不用按tab,可以直接寫protobuf-compiler,  顯示:沒有此文件

After these steps you are sure that there is no already protobuf in your machine. you can do some of steps e.g. autoremove to make sure.

make sure you've tried installing:

這一步必須要執行:

sudo apt-get install libprotobuf-dev protobuf-compiler


then download protocol-buffer: https://developers.google.com/protocol-buffers/ for your OS.  可以從csdn上查找下載,google不通。
afterwards extract it in (Ubuntu)

$ tar zxvf protobuf-2.6.1.tar.gz
$ cd protobuf-2.6.1
$ ./configure                          這裏改成參考書中的形式:   ./configure  --prefix=/home/sf/local_install/


把/home/sf/local_install/bin/protoc 文件刪除,


$ make && make all.


生成新的 /home/sf/local_install/bin/protoc 


再對caffe進行

$ make

$ make test

$ make runtest

就可以把以上的錯誤解決了。

在執行./app之前,需要在命令提示符下 執行 :


$  export  LD_LIBRARY_PATH=/home/sf/caffe/build/lib:$LD_LIBRARY_PATH

$ ./app


以下是參考帖子中的內容,我的過程中沒有出現。


if you during make all for caffe faced with error : error while loading shared libraries: libprotoc.so.9: cannot open shared object file: No such file or directory
fix it simly by sudo ldconfig.
if make all in caffe directory gives you error during make all, try this:
mkdir build && cd build
and then make all.
In this way, it's rare that you encounter with any error during the installation regarding protobuf.
Hopefully helps.

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