环境
caffe 版本即为现在master 分支。
操作系统为mac OS Mojave 10.14.5
1.protobuf版本3.7.1出现错误:
CXX .build_release/src/caffe/proto/caffe.pb.cc
In file included from .build_release/src/caffe/proto/caffe.pb.cc:4:
In file included from .build_release/src/caffe/proto/caffe.pb.h:23:
In file included from /usr/local/include/google/protobuf/io/coded_stream.h:135:
/usr/local/include/google/protobuf/stubs/common.h:186:17: error: expected expression
OnShutdownRun([](const void* pp) { delete static_cast(pp); }, p);
^
In file included from .build_release/src/caffe/proto/caffe.pb.cc:4:
In file included from .build_release/src/caffe/proto/caffe.pb.h:24:
In file included from /usr/local/include/google/protobuf/arena.h:51:
/usr/local/include/google/protobuf/arena_impl.h:303:22: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
ArenaImpl(ArenaImpl&&) = delete;
^
/usr/local/include/google/protobuf/arena_impl.h:303:28: warning: deleted function definitions are a C++11 extension [-Wc++11-extensions]
ArenaImpl(ArenaImpl&&) = delete;
^
/usr/local/include/google/protobuf/arena_impl.h:304:33: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
ArenaImpl& operator=(ArenaImpl&&) = delete;
^
/usr/local/include/google/protobuf/arena_impl.h:304:39: warning: deleted function definitions are a C++11 extension [-Wc++11-extensions]
ArenaImpl& operator=(ArenaImpl&&) = delete;
^
In file included from .build_release/src/caffe/proto/caffe.pb.cc:4:
In file included from .build_release/src/caffe/proto/caffe.pb.h:24:
/usr/local/include/google/protobuf/arena.h:297:33: warning: variadic templates are a C++11 extension [-Wc++11-extensions]
template
^
/usr/local/include/google/protobuf/arena.h:298:68: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
PROTOBUF_ALWAYS_INLINE static T* CreateMessage(Arena* arena, Args&&... args) {
^
/usr/local/include/google/protobuf/arena.h:323:33: warning: variadic templates are a C++11 extension [-Wc++11-extensions]
template
^
/usr/local/include/google/protobuf/arena.h:324:61: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
PROTOBUF_ALWAYS_INLINE static T* Create(Arena* arena, Args&&... args) {
^
/usr/local/include/google/protobuf/arena.h:443:23: warning: variadic templates are a C++11 extension [-Wc++11-extensions]
template
^
/usr/local/include/google/protobuf/arena.h:444:40: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
static T* Construct(void* ptr, Args&&... args) {
^
/usr/local/include/google/protobuf/arena.h:472:33: warning: variadic templates are a C++11 extension [-Wc++11-extensions]
template
^
/usr/local/include/google/protobuf/arena.h:474:62: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
Args&&... args) {
^
/usr/local/include/google/protobuf/arena.h:500:33: warning: variadic templates are a C++11 extension [-Wc++11-extensions]
template
^
/usr/local/include/google/protobuf/arena.h:502:55: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
Args&&... args) {
^
/usr/local/include/google/protobuf/arena.h:540:35: warning: variadic templates are a C++11 extension [-Wc++11-extensions]
template
^
/usr/local/include/google/protobuf/arena.h:543:63: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
Args&&... args) {
^
/usr/local/include/google/protobuf/arena.h:547:33: warning: variadic templates are a C++11 extension [-Wc++11-extensions]
template
^
/usr/local/include/google/protobuf/arena.h:550:61: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
Args&&... args) {
^
/usr/local/include/google/protobuf/arena.h:554:33: warning: variadic templates are a C++11 extension [-Wc++11-extensions]
template
^
/usr/local/include/google/protobuf/arena.h:556:59: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
Args&&... args) {
^
/usr/local/include/google/protobuf/arena.h:561:33: warning: variadic templates are a C++11 extension [-Wc++11-extensions]
template
^
/usr/local/include/google/protobuf/arena.h:563:56: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
Args&&... args) {
^
/usr/local/include/google/protobuf/arena.h:570:33: warning: variadic templates are a C++11 extension [-Wc++11-extensions]
template
^
/usr/local/include/google/protobuf/arena.h:573:56: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
Args&&... args) {
^
/usr/local/include/google/protobuf/arena.h:592:33: warning: variadic templates are a C++11 extension [-Wc++11-extensions]
template
^
/usr/local/include/google/protobuf/arena.h:594:42: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
Args&&... args) {
^
/usr/local/include/google/protobuf/arena.h:598:33: warning: variadic templates are a C++11 extension [-Wc++11-extensions]
template
^
/usr/local/include/google/protobuf/arena.h:599:49: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
PROTOBUF_ALWAYS_INLINE T* DoCreateMessage(Args&&... args) {
^
In file included from .build_release/src/caffe/proto/caffe.pb.cc:4:
In file included from .build_release/src/caffe/proto/caffe.pb.h:26:
In file included from /usr/local/include/google/protobuf/generated_message_table_driven.h:34:
In file included from /usr/local/include/google/protobuf/map.h:49:
In file included from /usr/local/include/google/protobuf/map_type_handler.h:35:
In file included from /usr/local/include/google/protobuf/wire_format_lite_inl.h:45:
In file included from /usr/local/include/google/protobuf/message_lite.h:47:
/usr/local/include/google/protobuf/stubs/once.h:41:19: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using once_flag = std::once_flag;
^
/usr/local/include/google/protobuf/stubs/once.h:42:19: warning: variadic templates are a C++11 extension [-Wc++11-extensions]
template
^
/usr/local/include/google/protobuf/stubs/once.h:43:20: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
void call_once(Args&&... args ) {
^
In file included from .build_release/src/caffe/proto/caffe.pb.cc:4:
In file included from .build_release/src/caffe/proto/caffe.pb.h:26:
In file included from /usr/local/include/google/protobuf/generated_message_table_driven.h:34:
In file included from /usr/local/include/google/protobuf/map.h:49:
In file included from /usr/local/include/google/protobuf/map_type_handler.h:35:
In file included from /usr/local/include/google/protobuf/wire_format_lite_inl.h:45:
/usr/local/include/google/protobuf/message_lite.h:136:3: error: unknown type name 'constexpr'
constexpr const T& get() const { return reinterpret_cast(union_); }
^
/usr/local/include/google/protobuf/message_lite.h:136:13: error: expected member name or ';' after declaration specifiers
constexpr const T& get() const { return reinterpret_cast(union_); }
~~~~~~~~~ ^
/usr/local/include/google/protobuf/message_lite.h:129:11: error: use of undeclared identifier 'union_'
new (&union_) T();
^
/usr/local/include/google/protobuf/message_lite.h:133:5: error: use of undeclared identifier 'get_mutable'
get_mutable()->~T();
^
/usr/local/include/google/protobuf/message_lite.h:150:45: error: found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?
PROTOBUF_EXPORT extern ExplicitlyConstructed<::std::string>
^~~
< ::
/usr/local/include/google/protobuf/message_lite.h:155:37: error: no member named 'get' in 'google::protobuf::internal::ExplicitlyConstructed >'
return fixed_address_empty_string.get();
~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
/usr/local/include/google/protobuf/message_lite.h:513:3: error: unknown type name 'constexpr'
constexpr bool alias = flags & kMergeWithAliasing;
^
/usr/local/include/google/protobuf/message_lite.h:513:13: error: expected unqualified-id
constexpr bool alias = flags & kMergeWithAliasing;
^
/usr/local/include/google/protobuf/message_lite.h:514:41: error: use of undeclared identifier 'alias'
return internal::MergePartialFromImpl(input, this) &&
^
In file included from .build_release/src/caffe/proto/caffe.pb.cc:4:
In file included from .build_release/src/caffe/proto/caffe.pb.h:26:
In file included from /usr/local/include/google/protobuf/generated_message_table_driven.h:34:
In file included from /usr/local/include/google/protobuf/map.h:49:
In file included from /usr/local/include/google/protobuf/map_type_handler.h:35:
In file included from /usr/local/include/google/protobuf/wire_format_lite_inl.h:46:
In file included from /usr/local/include/google/protobuf/repeated_field.h:61:
/usr/local/include/google/protobuf/implicit_weak_message.h:62:35: warning: 'override' keyword is a C++11 extension [-Wc++11-extensions]
std::string GetTypeName() const override { return ""; }
^
/usr/local/include/google/protobuf/implicit_weak_message.h:64:28: warning: 'override' keyword is a C++11 extension [-Wc++11-extensions]
MessageLite* New() const override { return new ImplicitWeakMessage; }
^
/usr/local/include/google/protobuf/implicit_weak_message.h:65:40: warning: 'override' keyword is a C++11 extension [-Wc++11-extensions]
MessageLite* New(Arena* arena) const override {
^
/usr/local/include/google/protobuf/implicit_weak_message.h:69:27: warning: 'override' keyword is a C++11 extension [-Wc++11-extensions]
Arena* GetArena() const override { return arena_; }
^
/usr/local/include/google/protobuf/implicit_weak_message.h:71:16: warning: 'override' keyword is a C++11 extension [-Wc++11-extensions]
void Clear() override { data_.clear(); }
^
/usr/local/include/google/protobuf/implicit_weak_message.h:73:30: warning: 'override' keyword is a C++11 extension [-Wc++11-extensions]
bool IsInitialized() const override { return true; }
^
/usr/local/include/google/protobuf/implicit_weak_message.h:75:56: warning: 'override' keyword is a C++11 extension [-Wc++11-extensions]
void CheckTypeAndMergeFrom(const MessageLite& other) override {
^
/usr/local/include/google/protobuf/implicit_weak_message.h:79:65: warning: 'override' keyword is a C++11 extension [-Wc++11-extensions]
bool MergePartialFromCodedStream(io::CodedInputStream* input) override;
^
/usr/local/include/google/protobuf/implicit_weak_message.h:88:31: warning: 'override' keyword is a C++11 extension [-Wc++11-extensions]
size_t ByteSizeLong() const override { return data_.size(); }
^
/usr/local/include/google/protobuf/implicit_weak_message.h:90:70: warning: 'override' keyword is a C++11 extension [-Wc++11-extensions]
void SerializeWithCachedSizes(io::CodedOutputStream* output) const override {
^
/usr/local/include/google/protobuf/implicit_weak_message.h:94:29: warning: 'override' keyword is a C++11 extension [-Wc++11-extensions]
int GetCachedSize() const override { return static_cast(data_.size()); }
^
In file included from .build_release/src/caffe/proto/caffe.pb.cc:4:
In file included from .build_release/src/caffe/proto/caffe.pb.h:26:
In file included from /usr/local/include/google/protobuf/generated_message_table_driven.h:34:
In file included from /usr/local/include/google/protobuf/map.h:49:
In file included from /usr/local/include/google/protobuf/map_type_handler.h:35:
In file included from /usr/local/include/google/protobuf/wire_format_lite_inl.h:46:
/usr/local/include/google/protobuf/repeated_field.h:119:21: warning: 'final' keyword is a C++11 extension [-Wc++11-extensions]
class RepeatedField final {
^
/usr/local/include/google/protobuf/repeated_field.h:130:30: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
RepeatedField(RepeatedField&& other) noexcept;
^
/usr/local/include/google/protobuf/repeated_field.h:130:39: error: expected ';' at end of declaration list
RepeatedField(RepeatedField&& other) noexcept;
^
;
/usr/local/include/google/protobuf/repeated_field.h:131:41: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
RepeatedField& operator=(RepeatedField&& other) noexcept;
^
/usr/local/include/google/protobuf/repeated_field.h:131:50: error: expected ';' at end of declaration list
RepeatedField& operator=(RepeatedField&& other) noexcept;
^
;
/usr/local/include/google/protobuf/repeated_field.h:480:38: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
void Add(typename TypeHandler::Type&& value,
^
/usr/local/include/google/protobuf/repeated_field.h:748:59: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
static inline std::string* New(Arena* arena, std::string&& value) {
^
/usr/local/include/google/protobuf/repeated_field.h:775:24: warning: 'final' keyword is a C++11 extension [-Wc++11-extensions]
class RepeatedPtrField final : private internal::RepeatedPtrFieldBase {
^
/usr/local/include/google/protobuf/repeated_field.h:787:36: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
RepeatedPtrField(RepeatedPtrField&& other) noexcept;
^
/usr/local/include/google/protobuf/repeated_field.h:787:45: error: expected ';' at end of declaration list
RepeatedPtrField(RepeatedPtrField&& other) noexcept;
^
;
/usr/local/include/google/protobuf/repeated_field.h:788:47: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
RepeatedPtrField& operator=(RepeatedPtrField&& other) noexcept;
^
/usr/local/include/google/protobuf/repeated_field.h:788:56: error: expected ';' at end of declaration list
RepeatedPtrField& operator=(RepeatedPtrField&& other) noexcept;
^
;
/usr/local/include/google/protobuf/repeated_field.h:796:19: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
void Add(Element&& value);
^
/usr/local/include/google/protobuf/repeated_field.h:1097:59: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
inline RepeatedField::RepeatedField(RepeatedField&& other) noexcept
^
/usr/local/include/google/protobuf/repeated_field.h:1097:32: error: out-of-line declaration of a member must be a definition [-Wout-of-line-declaration]
inline RepeatedField::RepeatedField(RepeatedField&& other) noexcept
~~~~~~~~~~~~~~~~~~~~~~~~^
/usr/local/include/google/protobuf/repeated_field.h:1097:68: error: expected ';' at end of declaration
inline RepeatedField::RepeatedField(RepeatedField&& other) noexcept
^
;
/usr/local/include/google/protobuf/repeated_field.h:1097:69: error: unknown type name 'noexcept'
inline RepeatedField::RepeatedField(RepeatedField&& other) noexcept
^
/usr/local/include/google/protobuf/repeated_field.h:1098:5: error: expected unqualified-id
: RepeatedField() {
^
/usr/local/include/google/protobuf/repeated_field.h:1110:18: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
RepeatedField&& other) noexcept {
^
/usr/local/include/google/protobuf/repeated_field.h:1109:56: error: out-of-line declaration of a member must be a definition [-Wout-of-line-declaration]
inline RepeatedField& RepeatedField::operator=(
~~~~~~~~~~~~~~~~~~~~~~~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
53 warnings and 20 errors generated.
这个原因是C++版本应当使用C++11,需要在caffe的MakeFile下将:
CXXFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS)
修改为
CXXFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS) -std=c++11
2.protobuf版本2.6.1,编译caffe时出现错误:
CXX .build_release/src/caffe/proto/caffe.pb.cc
In file included from .build_release/src/caffe/proto/caffe.pb.cc:4:
.build_release/src/caffe/proto/caffe.pb.h:10:10: fatal error: 'google/protobuf/port_def.inc' file not found
#include
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
找不到这个port_def.inc文件,因为这个版本caffe就不能用2.6.1的protobuf编译,这个版本的protobuf压根没有这个port_def.inc文件
3.缺失blas
报错信息为:
n file included from src/caffe/data_transformer.cpp:10:
In file included from ./include/caffe/util/math_functions.hpp:11:
./include/caffe/util/mkl_alternate.hpp:14:10: fatal error: 'cblas.h' file not found
#include
^~~~~~~~~
1 error generated.
解决办法:
修改caffe的MakeFile.config文件中的如下几行
BLAS := atlas
# BLAS_INCLUDE := $(shell brew --prefix openblas)/include
# BLAS_LIB := $(shell brew --prefix openblas)/lib
为:
BLAS := open
BLAS_INCLUDE := $(shell brew --prefix openblas)/include
BLAS_LIB := $(shell brew --prefix openblas)/lib
4.make all成功,在make test的时候出现类似2的错误
错误如下:
CXX/LD -o .build_release/test/test_all.testbin src/caffe/test/test_caffe_main.cpp
In file included from src/caffe/test/test_caffe_main.cpp:1:
In file included from ./include/caffe/caffe.hpp:7:
In file included from ./include/caffe/blob.hpp:9:
In file included from .build_release/src/caffe/proto/caffe.pb.h:23:
In file included from /usr/local/include/google/protobuf/io/coded_stream.h:135:
/usr/local/include/google/protobuf/stubs/common.h:186:17: error: expected expression
OnShutdownRun([](const void* pp) { delete static_cast(pp); }, p);
解决办法:
在caffe的makefile中修改:
ifeq ($(OSX), 1)
CXX := /usr/bin/clang++
成为:
ifeq ($(OSX), 1)
CXX := /usr/bin/clang++ -std=c++11
在CmakeList.txt中添加:
# use c++ 11
add_definitions(-std=c++11)
修改
if(UNIX OR APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall")
endif()
成为:
if(UNIX OR APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -std=c++11")
endif()
因为估摸着还是c++11的问题,所以改了几处有c++的,不知道哪处起了作用,觉得改的makefile中的哪一行起的作用。
5.Undefined symbols for architecture x86_64:
错误如下:
Undefined symbols for architecture x86_64:
"cv::imread(cv::String const&, int)", referenced from:
caffe::WindowDataLayer::load_batch(caffe::Batch*) in window_data_layer.o
caffe::WindowDataLayer::load_batch(caffe::Batch*) in window_data_layer.o
caffe::ReadImageToCVMat(std::__1::basic_string, std::__1::allocator > const&, int, int, bool) in io.o
"cv::imdecode(cv::_InputArray const&, int)", referenced from:
caffe::DecodeDatumToCVMatNative(caffe::Datum const&) in io.o
caffe::DecodeDatumToCVMat(caffe::Datum const&, bool) in io.o
"cv::imencode(cv::String const&, cv::_InputArray const&, std::__1::vector >&, std::__1::vector > const&)", referenced from:
caffe::ReadImageToDatum(std::__1::basic_string, std::__1::allocator > const&, int, int, int, bool, std::__1::basic_string, std::__1::allocator > const&, caffe::Datum*) in io.o
ld: symbol(s) not found for architecture x86_64
解决方法为:
在MakeFile中LIBRARIES += glog gflags protobuf boost_system boost_filesystem m后面添加:
LIBRARIES += opencv_imgcodecs opencv_highgui opencv_imgproc opencv_core
6.ld: library not found for -lboost_python
错误信息如下:
ld: library not found for -lboost_python
clang: error: linker command failed with exit code 1 (use -v to see invocation)
明明安装了boost-python,还是报错。这个错也是十分沙雕的,在/usr/local/lib中找到 libboost_python27.a重命名为libboost_python.a就可以了。
7.安装好后import caffe出错
找不到caffe模块,No module named caffe。需要打开~/.bash_profile
open ~/.bash_profile
然后在后面添加:
export PYTHONPATH=/Users/hdychi/caffe/python:$PYTHONPATH
/Users/hdychi/caffe即为caffe文件夹的目录。
然后运行一下:
source ~/.bash_profile
就可以import caffe了。
吐槽
感觉我仿佛把装caffe能踩着了的坑都踩了一遍,踩坑小能手绝不认输