在编译自己的caffe相关的程序的过程中,突然出现了如下错误(之前是正常的编译通过的):
/usr/local/caffe/include/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
^
/usr/local/caffe/include/caffe/proto/caffe.pb.h:18:2: error: #error incompatible with your Protocol Buffer headers. Please
#error incompatible with your Protocol Buffer headers. Please
^
/usr/local/caffe/include/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.
此时按照错误信息的路径找到该文件并打开,看到如下内容:
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: caffe.proto
#ifndef PROTOBUF_caffe_2eproto__INCLUDED
#define PROTOBUF_caffe_2eproto__INCLUDED
#include <string>
#include <google/protobuf/stubs/common.h>
#if GOOGLE_PROTOBUF_VERSION < 2006000
#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 2006001 < 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
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/message.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/extension_set.h>
#include <google/protobuf/generated_enum_reflection.h>
#include <google/protobuf/unknown_field_set.h>
可以看到这个文件是编译caffe时候生成的,并且它所要求的protobuf版本是2.6.0或2.6.1,高于或低于都会出现error
此时需要查看系统的protobuf的版本是多少:
命令行输入 protoc --version
显示:libprotoc 3.5.0
确实因为某次升级将protobuf的版本升级到了3.5.0,在运行程序时protoc的版本是3.5.0,但是程序中的caffe.pb.h文件是由2.6.1版本的protoc生成的,所以产生了上述error。
解决方案:
在caffe目录下重新编译:
make clean
make all -j4
然后如果需要将caffe相关的内容安装到系统目录则:
sudo make install
此时再次编译原来的工程,error消失,编译通过。