1. 程式人生 > >CentOs7下,Caffe環境安裝問題解決

CentOs7下,Caffe環境安裝問題解決

準備在CentOS 7 下重新安裝Caffe,centos7很不錯,基本上官方文件裡的:

sudo yum install protobuf-devel leveldb-devel snappy-devel opencv-devel boost-devel hdf5-devel
sudo yum install gflags-devel glog-devel lmdb-devel
可以順利執行完成,接著根據文件:

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).

安裝atlas-devel。

開始編譯~

make all 

報錯:

[[email protected]**** 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:

[[email protected]*** 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

後續一切成功。 done。

建議Caffe對CentOS 7 下atlas引用失敗的問題做修復。有空提個issue。