MacBook Pro / OS X 10.10.3 (Yosemite) 编译caffe小记

就一个关键点:编译时c++标准库使用libstdc++,原因不解释了

caffe为git库中最新版本:

git init

git pull https://github.com/BVLC/caffe.git


其它按照官方安装提示做就行,我选用的搭配是官方推荐的anaconda python / Intel MKL / cuDNN, 有三个小处需要注意:

opencv选用3.0.0:(2.4.X 也应该可以,个人喜好新版本,因此换做3了,如果用的2.4.x,那下文的caffe里的Makefile的LIBRARIES就不用修改

brew install --build-from-source -vd homebrew/science/opencv3

protobuf:安装过程可能会出现安装失败提示,需要手工删除文件以及创建连接覆盖,按编译出错提示照做一遍

boost,boost-python: 使用1.57.0版本,其它版本未验证,可能存在编译失败。


最后一个修改点,官方没有提到:

caffe编译过程也需要在编译器后边添加-stdlib=libstdc++,我的改动如下:

diff --git a/Makefile b/Makefile
index 05b783a..a8b135b 100644
--- a/Makefile
+++ b/Makefile
@@ -171,7 +171,7 @@ ifneq ($(CPU_ONLY), 1)
 endif
 LIBRARIES += glog gflags protobuf leveldb snappy \
        lmdb boost_system hdf5_hl hdf5 m \
-       opencv_core opencv_highgui opencv_imgproc
+       opencv_core opencv_imgcodecs opencv_highgui opencv_imgproc
 PYTHON_LIBRARIES := boost_python python2.7
 WARNINGS := -Wall -Wno-sign-compare
 
@@ -349,11 +349,16 @@ CXXFLAGS += -MMD -MP
 
 # Complete build flags.
 COMMON_FLAGS += $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir))
-CXXFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS)
-NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
-# mex may invoke an older gcc that is too liberal with -Wuninitalized
+ifeq ($(OSX), 1)
+       CXXFLAGS += -stdlib=libstdc++ $(COMMON_FLAGS) $(WARNINGS)
+       NVCCFLAGS += -ccbin=$(CXX) -Xcompiler "-fPIC -stdlib=libstdc++" $(COMMON_FLAGS)
+       LINKFLAGS += -fPIC -stdlib=libstdc++ -lstdc++ $(COMMON_FLAGS) $(WARNINGS)
+else
+       CXXFLAGS += -fPIC $(COMMON_FLAGS) $(WARNINGS)
+       NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
+       LINKFLAGS += -fPIC -lstdc++ $(COMMON_FLAGS) $(WARNINGS)
+endif
 MATLAB_CXXFLAGS := $(CXXFLAGS) -Wno-uninitialized
-LINKFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS)

你可能感兴趣的:(MacBook Pro / OS X 10.10.3 (Yosemite) 编译caffe小记)