Install Caffe on Mac error: "fatal error: 'cblas.h' file not found"
Install Caffe on Mac error: "fatal error: 'cblas.h' file not found"
我一直在关注 this guide 在我的 El Capitan macbook pro 上安装,使用 CMake 构建 makefile。但是,当我尝试制作时,我 运行 进入了缺少 cblas.h 文件的错误。我成功地重新安装了 openblas:
$ brew uninstall openblas; brew install --fresh -vd openblas
并添加两个构建标志:
LDFLAGS: -L/usr/local/opt/openblas/lib
CPPFLAGS: -I/usr/local/opt/openblas/include
但是我仍然得到错误。然后我重新安装了 CUDA 和 xcode-select 推荐的安装工具 here。
任何 recommendations/further 为什么 make 看不到我的 cblas.h 文件的猜测都将受到赞赏!
在你的问题中我看到 cmake
,但在提供 link Makefile.config
.
如果你还想继续 cmake:
首先,构建脚本没有损坏 - 我在 Yosemite 上使用最新的 master 分支 (2016-02-25) 进行了尝试,但如果你已经这样做了,你应该稍微调整一下制作
brew uninstall openblas; brew install --fresh -vd openblas
只是 运行 你的 cmake 和额外的参数:
cmake -DCMAKE_CXX_FLAGS=-I/usr/local/opt/openblas/include <path to your sources>
然后是通常的 make 或 xcode build(取决于您使用的生成器)。
此后它在我的系统上成功构建。
UPD: 您还可以使用 Accelerate.framework
(vecLib
) 中的库而不是 openblas。
我今天 运行 自己解决了这个问题,并向主线 Caffe 提交了拉取请求:
https://github.com/BVLC/caffe/pull/4247
对我来说,问题是 Caffe 正在寻找已弃用的 vecLib 框架(未发布 cblas.h)而不是新的 Accelerate 框架(已发布 cblas.h)。
转到 Makefile.config
并使用您的 openblas 所在的路径编辑以下行,在我的例子中版本是 0.2.18_2
一定要取消注释这些行:
BLAS_INCLUDE := /usr/local/Cellar/openblas/0.2.18_2/include
BLAS_LIB := /usr/local/Cellar/openblas/0.2.18_2/lib
取消注释 Makefile.config 中的这一行:
# Homebrew puts openblas in a directory that is not on the standard search path
BLAS_INCLUDE := $(shell brew --prefix openblas)/include
BLAS_LIB := $(shell brew --prefix openblas)/lib
在Makefile.config
中:
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/local/opt/openblas/include/
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/local/opt/openblas/lib/
不确定这是否是最优雅的解决方案,但它确实有效。
对于我的 Caffe 安装,这是我的设置:
- MacOS 10.12 Sierra,CPU_ONLY=ON,无 CUDA,无 Anaconda,具有 Python 接口
- 通过 Make 编译(而不是 Cmake)official instructions here
我的 cblas.h
文件的目录(通过 Finder 搜索):
/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Headers
将 cblas.h 路径添加到 ./caffe/Makefile.config
:
# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Headers/
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
补充说明
另外对我来说,我有 OpenBlas。可能会影响您的情况。
# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := open
我还用 cblas.h 路径修改了 ./caffe/Makefile
,但不确定是否有必要/有所不同。
else ifeq ($(BLAS), open)
# OpenBLAS
LIBRARIES += openblas
BLAS_INCLUDE ?= /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Headers/
结果
原来的错误消失了:
Tams-MacBook-Pro:caffe tamtam$ make all
CXX src/caffe/blob.cpp
In file included from src/caffe/blob.cpp:7:
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 <cblas.h>
^
1 error generated.
make: *** [.build_release/src/caffe/blob.o] Error 1
但是下一个错误是(输出的尾端):
CXX src/caffe/util/upgrade_proto.cpp
AR -o .build_release/lib/libcaffe.a
/Applications/Xcode833.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_conv_layer.o) has no symbols
/Applications/Xcode833.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_lcn_layer.o) has no symbols
/Applications/Xcode833.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_lrn_layer.o) has no symbols
/Applications/Xcode833.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_pooling_layer.o) has no symbols
/Applications/Xcode833.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_relu_layer.o) has no symbols
/Applications/Xcode833.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_sigmoid_layer.o) has no symbols
/Applications/Xcode833.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_softmax_layer.o) has no symbols
/Applications/Xcode833.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_tanh_layer.o) has no symbols
/Applications/Xcode833.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(parallel.o) has no symbols
/Applications/Xcode833.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn.o) has no symbols
LD -o .build_release/lib/libcaffe.so.1.0.0-rc5
clang: warning: argument unused during compilation: '-pthread' [-Wunused-command-line-argument]
ld: warning: directory not found for option '-L/lib'
ld: library not found for -lopenblas
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [.build_release/lib/libcaffe.so.1.0.0-rc5] Error 1
我fix/resolve/modify通过这个在Makefile.config
:
# Homebrew puts openblas in a directory that is not on the standard search path
BLAS_INCLUDE := $(brew --prefix openblas)/include /usr/local/Cellar/openblas/0.3.3/include
BLAS_LIB := $(brew --prefix openblas)/lib /usr/local/Cellar/openblas/0.3.3/lib
我也在 Makefile
中解决了 -pthread
警告:
CXXFLAGS += -fPIC $(COMMON_FLAGS) $(WARNINGS) -std=c++11 #rm'd -pthread
LINKFLAGS += -fPIC $(COMMON_FLAGS) $(WARNINGS) -std=c++11 #rm'd -pthread
对于另一个 make clean
、cp Makefile.config.example Makefile.config
和 make all
,这是输出的尾端,同样是输出的整个要点:
In file included from ./include/caffe/caffe.hpp:12:
./include/caffe/net.hpp:41:5: warning: unused typedef 'INVALID_REQUESTED_LOG_SEVERITY' [-Wunused-local-typedef]
LOG_EVERY_N(WARNING, 1000) << "DEPRECATED: ForwardPrefilled() "
^
/usr/local/include/glog/logging.h:943:30: note: expanded from macro 'LOG_EVERY_N'
INVALID_REQUESTED_LOG_SEVERITY); \
^
1 warning generated.
CXX/LD -o .build_release/examples/cpp_classification/classification.bin
ld: warning: directory not found for option '-L/lib'
CXX examples/mnist/convert_mnist_data.cpp
CXX/LD -o .build_release/examples/mnist/convert_mnist_data.bin
ld: warning: directory not found for option '-L/lib'
CXX examples/siamese/convert_mnist_siamese_data.cpp
CXX/LD -o .build_release/examples/siamese/convert_mnist_siamese_data.bin
ld: warning: directory not found for option '-L/lib'
所以看起来 make all
构建成功,假设这个 -L/lib
错误不会导致进一步的问题。注意:make all
、make test
和 make runtest
运行 很好,只是产生了警告。 make pycaffe
然而产生了进一步的错误;稍后我可能 link 到我的解决方案。另外,是的,这个答案确实很长,超出了 OP 的要求,但希望我的回答可以在这个可怕的安装过程中帮助其他人。
我一直在关注 this guide 在我的 El Capitan macbook pro 上安装,使用 CMake 构建 makefile。但是,当我尝试制作时,我 运行 进入了缺少 cblas.h 文件的错误。我成功地重新安装了 openblas:
$ brew uninstall openblas; brew install --fresh -vd openblas
并添加两个构建标志:
LDFLAGS: -L/usr/local/opt/openblas/lib
CPPFLAGS: -I/usr/local/opt/openblas/include
但是我仍然得到错误。然后我重新安装了 CUDA 和 xcode-select 推荐的安装工具 here。
任何 recommendations/further 为什么 make 看不到我的 cblas.h 文件的猜测都将受到赞赏!
在你的问题中我看到 cmake
,但在提供 link Makefile.config
.
如果你还想继续 cmake:
首先,构建脚本没有损坏 - 我在 Yosemite 上使用最新的 master 分支 (2016-02-25) 进行了尝试,但如果你已经这样做了,你应该稍微调整一下制作
brew uninstall openblas; brew install --fresh -vd openblas
只是 运行 你的 cmake 和额外的参数:
cmake -DCMAKE_CXX_FLAGS=-I/usr/local/opt/openblas/include <path to your sources>
然后是通常的 make 或 xcode build(取决于您使用的生成器)。
此后它在我的系统上成功构建。
UPD: 您还可以使用 Accelerate.framework
(vecLib
) 中的库而不是 openblas。
我今天 运行 自己解决了这个问题,并向主线 Caffe 提交了拉取请求:
https://github.com/BVLC/caffe/pull/4247
对我来说,问题是 Caffe 正在寻找已弃用的 vecLib 框架(未发布 cblas.h)而不是新的 Accelerate 框架(已发布 cblas.h)。
转到 Makefile.config
并使用您的 openblas 所在的路径编辑以下行,在我的例子中版本是 0.2.18_2
一定要取消注释这些行:
BLAS_INCLUDE := /usr/local/Cellar/openblas/0.2.18_2/include
BLAS_LIB := /usr/local/Cellar/openblas/0.2.18_2/lib
取消注释 Makefile.config 中的这一行:
# Homebrew puts openblas in a directory that is not on the standard search path
BLAS_INCLUDE := $(shell brew --prefix openblas)/include
BLAS_LIB := $(shell brew --prefix openblas)/lib
在Makefile.config
中:
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/local/opt/openblas/include/
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/local/opt/openblas/lib/
不确定这是否是最优雅的解决方案,但它确实有效。
对于我的 Caffe 安装,这是我的设置:
- MacOS 10.12 Sierra,CPU_ONLY=ON,无 CUDA,无 Anaconda,具有 Python 接口
- 通过 Make 编译(而不是 Cmake)official instructions here
我的 cblas.h
文件的目录(通过 Finder 搜索):
/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Headers
将 cblas.h 路径添加到 ./caffe/Makefile.config
:
# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Headers/
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
补充说明
另外对我来说,我有 OpenBlas。可能会影响您的情况。
# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := open
我还用 cblas.h 路径修改了 ./caffe/Makefile
,但不确定是否有必要/有所不同。
else ifeq ($(BLAS), open)
# OpenBLAS
LIBRARIES += openblas
BLAS_INCLUDE ?= /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Headers/
结果
原来的错误消失了:
Tams-MacBook-Pro:caffe tamtam$ make all
CXX src/caffe/blob.cpp
In file included from src/caffe/blob.cpp:7:
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 <cblas.h>
^
1 error generated.
make: *** [.build_release/src/caffe/blob.o] Error 1
但是下一个错误是(输出的尾端):
CXX src/caffe/util/upgrade_proto.cpp
AR -o .build_release/lib/libcaffe.a
/Applications/Xcode833.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_conv_layer.o) has no symbols
/Applications/Xcode833.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_lcn_layer.o) has no symbols
/Applications/Xcode833.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_lrn_layer.o) has no symbols
/Applications/Xcode833.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_pooling_layer.o) has no symbols
/Applications/Xcode833.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_relu_layer.o) has no symbols
/Applications/Xcode833.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_sigmoid_layer.o) has no symbols
/Applications/Xcode833.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_softmax_layer.o) has no symbols
/Applications/Xcode833.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_tanh_layer.o) has no symbols
/Applications/Xcode833.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(parallel.o) has no symbols
/Applications/Xcode833.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn.o) has no symbols
LD -o .build_release/lib/libcaffe.so.1.0.0-rc5
clang: warning: argument unused during compilation: '-pthread' [-Wunused-command-line-argument]
ld: warning: directory not found for option '-L/lib'
ld: library not found for -lopenblas
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [.build_release/lib/libcaffe.so.1.0.0-rc5] Error 1
我fix/resolve/modify通过这个在Makefile.config
:
# Homebrew puts openblas in a directory that is not on the standard search path
BLAS_INCLUDE := $(brew --prefix openblas)/include /usr/local/Cellar/openblas/0.3.3/include
BLAS_LIB := $(brew --prefix openblas)/lib /usr/local/Cellar/openblas/0.3.3/lib
我也在 Makefile
中解决了 -pthread
警告:
CXXFLAGS += -fPIC $(COMMON_FLAGS) $(WARNINGS) -std=c++11 #rm'd -pthread
LINKFLAGS += -fPIC $(COMMON_FLAGS) $(WARNINGS) -std=c++11 #rm'd -pthread
对于另一个 make clean
、cp Makefile.config.example Makefile.config
和 make all
,这是输出的尾端,同样是输出的整个要点:
In file included from ./include/caffe/caffe.hpp:12:
./include/caffe/net.hpp:41:5: warning: unused typedef 'INVALID_REQUESTED_LOG_SEVERITY' [-Wunused-local-typedef]
LOG_EVERY_N(WARNING, 1000) << "DEPRECATED: ForwardPrefilled() "
^
/usr/local/include/glog/logging.h:943:30: note: expanded from macro 'LOG_EVERY_N'
INVALID_REQUESTED_LOG_SEVERITY); \
^
1 warning generated.
CXX/LD -o .build_release/examples/cpp_classification/classification.bin
ld: warning: directory not found for option '-L/lib'
CXX examples/mnist/convert_mnist_data.cpp
CXX/LD -o .build_release/examples/mnist/convert_mnist_data.bin
ld: warning: directory not found for option '-L/lib'
CXX examples/siamese/convert_mnist_siamese_data.cpp
CXX/LD -o .build_release/examples/siamese/convert_mnist_siamese_data.bin
ld: warning: directory not found for option '-L/lib'
所以看起来 make all
构建成功,假设这个 -L/lib
错误不会导致进一步的问题。注意:make all
、make test
和 make runtest
运行 很好,只是产生了警告。 make pycaffe
然而产生了进一步的错误;稍后我可能 link 到我的解决方案。另外,是的,这个答案确实很长,超出了 OP 的要求,但希望我的回答可以在这个可怕的安装过程中帮助其他人。