在Mac上安装Caffe出现错误:"致命错误:未找到'cblas.h'文件"

8
我一直在按照这个指南在我的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工具。
欢迎提出任何关于为什么make无法看到我的cblas.h文件的建议/进一步推测!

嗯...我刚刚尝试通过手动编辑makefile(而不是使用cmake)进行编译,一切都正常...我所做的就是取消注释anaconda行。似乎这个安装的cmake文件由于某种原因出了问题...我仔细检查了CUDA_cublas_LIBRARY构建变量,指向有效的“/usr/local/cuda/lib/libcublas.dylib”路径,但我仍然遇到了错误。如果有人能用Cmake使其工作,请解释一下! - Ethan Keller
对于那些试图使用makefile安装的人,这个网站提供了完整的分解说明!我发现它很有帮助。 - Ethan Keller
顺便提一下,cblas.hopenblas 或者 ATLAS 的一部分,而不是 CUDA blas 模块。 - avtomaton
请尝试此代码片段 https://gist.github.com/kylemcdonald/0698c7749e483cd43a0e - johndpope
你在哪里添加LDFLAGS和CPPFLAGS? - Mehmed
6个回答

18

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

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

更新:您还可以使用Accelerate.framework中的库(vecLib)而不是openblas


4

请前往 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

3

请在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

1

今天我自己遇到了这个问题,并向主线Caffe提交了一个拉取请求:

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

对我来说,问题在于Caffe找到了已弃用的vecLib框架(它不提供cblas.h),而没有找到新的Accelerate框架(它提供cblas.h)。

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/

不确定这是否是最优雅的解决方案,但它能够正常工作。


0

我的Caffe安装设置如下:

  • MacOS 10.12 Sierra,CPU_ONLY=ON,没有CUDA,没有Anaconda,使用Python接口
  • 通过Make进行编译(而不是Cmake)官方指南在此

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

我也修改了./caffe/Makefile中的cblas.h路径,但不确定是否必要或有所不同。

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

我也通过在 Makefile 中进行以下操作解决了“-pthread”警告: -pthread
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 的要求,但希望我的回答能帮助其他人解决这个可怕的安装过程。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接