General dependencies
sudo yum install protobuf-devel leveldb-devel snappy-devel opencv-devel boost-devel hdf5-devel
Remaining dependencies, recent OS
sudo yum install gflags-devel glog-devel lmdb-devel
Remaining dependencies, if not found
# glog
wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/google-glog/glog-0.3.3.tar.gz
tar zxvf glog-0.3.3.tar.gz
cd glog-0.3.3
./configure
make && make install
# gflags
wget https://github.com/schuhschuh/gflags/archive/master.zip
unzip master.zip
cd gflags-master
mkdir build && cd build
export CXXFLAGS="-fPIC" && cmake .. && make VERBOSE=1
make && make install
# lmdb
git clone https://github.com/LMDB/lmdb
cd lmdb/libraries/liblmdb
make && make install
BLAS
: install ATLAS by
sudo yum install atlas-devel
or install OpenBLAS or MKL for better CPU performance. For the Makefile build, uncomment and set
BLAS_LIB
accordingly as ATLAS is usually installed under
/usr/lib[64]/atlas
).
开始编译~
make all
报错:
[root@**** caffe]# make all
CXX/LD -o .build_release/tools/convert_imageset.bin
/bin/ld: cannot find -lcblas
/bin/ld: cannot find -latlas
collect2: error: ld returned 1 exit status
查了一下,是程序在我们配置的lib目录里找不到atlas的so文件,比对了一下ld命令的查找方式和我们已安装的atlas:
ld -latlas --verbose
显示查找路径如下:
==================================================
attempt to open /usr/x86_64-redhat-linux/lib64/libatlas.so failed
attempt to open /usr/x86_64-redhat-linux/lib64/libatlas.a failed
attempt to open /usr/lib64/libatlas.so failed
attempt to open /usr/lib64/libatlas.a failed
attempt to open /usr/local/lib64/libatlas.so failed
attempt to open /usr/local/lib64/libatlas.a failed
attempt to open /lib64/libatlas.so failed
attempt to open /lib64/libatlas.a failed
attempt to open /usr/x86_64-redhat-linux/lib/libatlas.so failed
attempt to open /usr/x86_64-redhat-linux/lib/libatlas.a failed
attempt to open /usr/local/lib/libatlas.so failed
attempt to open /usr/local/lib/libatlas.a failed
attempt to open /lib/libatlas.so failed
attempt to open /lib/libatlas.a failed
attempt to open /usr/lib/libatlas.so failed
attempt to open /usr/lib/libatlas.a failed
ld: cannot find -latlas
我看了一下我们安装的atlas,在/usr/lib64/atlas/下,内有这些so:
[root@*** caffe]# ll /usr/lib64/atlas
total 21304
lrwxrwxrwx 1 root root 17 Apr 6 04:38 libsatlas.so -> libsatlas.so.3.10
lrwxrwxrwx 1 root root 17 Mar 14 22:24 libsatlas.so.3 -> libsatlas.so.3.10
-rwxr-xr-x 1 root root 10852104 Nov 20 2015 libsatlas.so.3.10
lrwxrwxrwx 1 root root 17 Apr 6 04:38 libtatlas.so -> libtatlas.so.3.10
lrwxrwxrwx 1 root root 17 Mar 14 22:24 libtatlas.so.3 -> libtatlas.so.3.10
-rwxr-xr-x 1 root root 10959464 Nov 20 2015 libtatlas.so.3.10
我们安装的atlas的so库只有libsatlas和libtatlas两种,与caffe要的完全不匹配。
查了一些材料(https://www.centos.org/forums/viewtopic.php?t=48543),这个提问里有提到这个现象,在centOS7下,库名已改,引入方式也要改变:
Names and content of atlas libraries have changed recently. Try
-L/usr/lib64/atlas -lsatlas or -L/usr/lib64/atlas -ltatlas
instead of
-lcblas.
但我并不想去修改caffe源码,担心引起连锁问题,且报错中并没有提示具体发生问题的文件。
解决方案
改用openblas:
yum install openblas-devel
MakeFile.config配置如下:
BLAS := open
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
#BLAS_INCLUDE := /usr/include/atlas
#BLAS_LIB := /usr/lib64/atlas
后续报错/lib64/libgtk-x11-2.0.so.0: undefined reference to `g_type_check_instance_is_fundamentally_a'
问题是因为没有安装包导致的:
centos下面:
运行:
yum groupinstall "Development Tools"
yum install gtk+-devel gtk2-devel
make all
make test
make runtest
一切顺利
make pycaffe时会有错误出现主要是一些必要的python包没有安装。
for req in $(cat caffe/python/requirements.txt);
>do
>pip install $req;
>done
[root@caffe caffe-master]# make pycaffe
CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
python/caffe/_caffe.cpp:10:31: fatal error: numpy/arrayobject.h: No such file or directory
#include
vi Makefile.config 更改/usr/lib/python2.7/dist-packages/numpy/core/include 为/usr/lib64/python2.7/site-packages/numpy/core/include