在Mac上安装Caffe错误:“致命错误:找不到'cblas.h'文件”

时间:2016-02-22 01:20:28

标签: macos caffe

我一直关注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

但是我仍然得到错误。然后我按照推荐here重新安装了CUDA和xcode-select安装工具。

有关为什么make的任何建议/进一步推测都没有看到我的cblas.h文件,我们非常感谢!

5 个答案:

答案 0 :(得分:15)

在您的问题中,我看到了cmake,但提供了链接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构建(取决于你使用的生成器)。

之后,它在我的系统上成功构建。

UPD:您还可以使用Accelerate.frameworkvecLib)中的库代替 openblas

答案 1 :(得分:4)

转到-i并使用您的openblas所在的路径编辑以下行,在我的情况下,版本为Makefile.config

请务必取消注释这些行:

0.2.18_2

答案 2 :(得分:2)

在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

答案 3 :(得分:0)

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/

不确定这是否是最优雅的解决方案,但可以。

答案 4 :(得分:0)

对于我的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

我通过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

我也通过-pthread中的Makefile警告来解决:

CXXFLAGS += -fPIC $(COMMON_FLAGS) $(WARNINGS) -std=c++11 #rm'd -pthread
LINKFLAGS += -fPIC $(COMMON_FLAGS) $(WARNINGS) -std=c++11 #rm'd -pthread

对于另一个make cleancp Makefile.config.example Makefile.configmake 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 allmake testmake runtest仅在产生警告的情况下运行良好。 make pycaffe但是产生了进一步的错误;我稍后可能会链接到我的解决方案。另外,是的,这个答案确实很长,超出了OP的要求,但是希望我的答案可能会在这个可怕的安装过程中对其他人有所帮助。