报错源码——来自于caffe.ph.h

怎么生成caffe.pb.h的

if GOOGLE_PROTOBUF_VERSION < 2004000
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers.  Please update
#error your headers.
endif
if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers.  Please
#error regenerate this file with a newer version of protoc.
endif
问题原因

caffe.pb.h这个文件是由较新版本的protoc可执行程序产生的,protoc的版本较新,但是你现在安装的protobuf版本较老。也就是说,现在系统上有多个版本的protobuf。例如protobuf-2.6.1和protobuf-3.0.0你应该统一安装的protobuf版本。
比如:当前的protoc来自anaconda2下的bin,用anaconda安装protobuf,connda install protobuf,它自动安装最新版例如protobuf-3.0.0及相应的include,lib文件。
但是,caffe编译的时候,它是去寻找单独安装protobuf时的include和lib。
而这两种protobuf版本不一样,这就是问题产生原因,单独安装的protobuf与anaconda的版本不一致。

解决办法

一般来说,protobuf的bin,include,lib位于同一个文件夹。那么,你就要使得编译链接在寻找头文件库文件时(Makefile.config中)找的也是跟protoc对应的库文件。


我使用的环境是ubuntu。解决方法如下:

1 去github上下载2.5.0版本的protobuf。

网址如下:https://github.com/google/protobuf/releases/tag/v2.5.0

2 安装。我的protoc文件的最终位置为/usr/local/bin
下面以2.4.1为例。
首先自己设法下载一个源码包:
protobuf-2.4.1.tar.bz2,
假设放到/data目录下 1.安装protobuf
tar jxvf protobuf-2.4.1.tar.bz2
./configure
make
make check
sudo make install
sudo ldconfig # refresh shared library cache.
3 用which protoc命令找到当前protoc文件的位置。将2.5.0版本的protoc文件拷贝过去,覆盖原本的文件。

protoc --version  可查看当前protoc的版本。

回到caffe的路径下,make clean后重新安装即可。