1

I am trying to compile Caffe and am receiving the following error that I cannot debug:

ld: can't map file, errno=22 file '/usr/local/opt/openblas/lib' for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

I have downloaded OpenBLAS via brew install openblas and received the following potentially important output:

==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local.

macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/openblas/lib
    CPPFLAGS: -I/usr/local/opt/openblas/include

I added the necessary paths to my Makefile.config file, which is below:

# Refer to http://caffe.berkeleyvision.org/installation.html
# Contributions simplifying and improving our build system are welcome!

# cuDNN acceleration switch (uncomment to build with cuDNN).
# USE_CUDNN := 1

# CPU-only switch (uncomment to build without GPU support).
CPU_ONLY := 1

# To customize your choice of compiler, uncomment and set the following.
# N.B. the default for Linux is g++ and the default for OSX is clang++
# CUSTOM_CXX := g++

# CUDA directory contains bin/ and lib/ directories that we need.
CUDA_DIR := /usr/local/cuda
# On Ubuntu 14.04, if cuda tools are installed via
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
# CUDA_DIR := /usr

# CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the *_50 lines for compatibility.
CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
            -gencode arch=compute_20,code=sm_21 \
            -gencode arch=compute_30,code=sm_30 \
            -gencode arch=compute_35,code=sm_35 \
            -gencode arch=compute_50,code=sm_50 \
            -gencode arch=compute_50,code=compute_50

# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
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/local/opt/openblas/include
# BLAS_LIB := /usr/local/opt/openblas/lib

# 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

# This is required only if you will compile the matlab interface.
# MATLAB directory should contain the mex binary in /bin.
# MATLAB_DIR := /usr/local
# MATLAB_DIR := /Applications/MATLAB_R2012b.app

# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
# PYTHON_INCLUDE := /usr/include/python2.7 \
            # /usr/lib/python2.7/dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
ANACONDA_HOME := $(HOME)/anaconda
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
                  $(ANACONDA_HOME)/include/python2.7 \
                  $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \

# We need to be able to find libpythonX.X.so or .dylib.
# PYTHON_LIB := /usr/lib
PYTHON_LIB := $(ANACONDA_HOME)/lib

# Homebrew installs numpy in a non standard path (keg only)
# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core;      print(numpy.core.__file_$
# PYTHON_LIB += $(shell brew --prefix numpy)/lib

# Uncomment to support layers written in Python (will link against Python libs)
# WITH_PYTHON_LAYER := 1

# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib

# If Homebrew is installed at a non standard location (for example your home directory) $
# INCLUDE_DIRS += $(shell brew --prefix)/include
# LIBRARY_DIRS += $(shell brew --prefix)/lib

# Uncomment to use `pkg-config` to specify OpenCV library paths.
# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $
# USE_PKG_CONFIG := 1

BUILD_DIR := build
DISTRIBUTE_DIR := distribute

# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/iss$
# DEBUG := 1

# The ID of the GPU that 'make runtest' will use to run unit tests.
TEST_GPUID := 0

# enable pretty build (comment to see full commands)
Q ?= @
Melanie
  • 1,787
  • 3
  • 12
  • 15

1 Answers1

0

Rough but working method:

change the following line in the Makefile (not config)

LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) $(PKG_CONFIG) \ $(foreach library,$(LIBRARIES),-l$(library)) 

with

 LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) $(PKG_CONFIG) \ $(foreach library,$(LIBRARIES),-l$(library)) \ -I/usr/local/opt/openblas/include \ -L/usr/local/opt/openblas/lib
Riccardo Petraglia
  • 1,943
  • 1
  • 13
  • 25
  • I have edited those two lines and still get the same error. My changes were: `INCLUDE_DIRS := /usr/local/include /usr/local/opt/openblas/lib` and `LIBRARY_DIRS := /usr/local/lib /usr/lib /usr/local/opt/openblas/include` as there was nothing in my PYTHON_INCLUDE and PYTHON_LIB variables. – Melanie Oct 26 '16 at 20:39
  • What is the output of `shell brew --prefix openblas`? – Riccardo Petraglia Oct 26 '16 at 20:42
  • I never installed caffe... but do you have some `./config` to run before `make`? – Riccardo Petraglia Oct 26 '16 at 20:43
  • `/usr/local/opt/openblas`. And no, there is no executable config file. – Melanie Oct 26 '16 at 20:48
  • Do you see the blas libraries doing `ls /usr/local/opt/openblas/lib`? – Riccardo Petraglia Oct 26 '16 at 20:50
  • No, sorry... I am completely wrong... The point is that or you installed the wrong libraries or you are trying to install the wrong caffe – Riccardo Petraglia Oct 26 '16 at 20:52
  • I do see all the `*.dylib` libraries. I'm not sure how else I would install openblas. Maybe I will just use Atlas or MLK instead. – Melanie Oct 26 '16 at 20:56
  • could you give me the output of `uname -a`? (I suppose mac works as GNU/linux in this stuff) – Riccardo Petraglia Oct 26 '16 at 20:56
  • `Darwin Trends-MacBook-Pro.local 15.6.0 Darwin Kernel Version 15.6.0: Mon Aug 29 20:21:34 PDT 2016; root:xnu-3248.60.11~1/RELEASE_X86_64 x86_64` – Melanie Oct 26 '16 at 21:02
  • Try like this: into the `Makefile` (not the config) at line 421 add `-I/usr/local/opt/openblas/include` and `-L/usr/local/opt/openblas/lib` (the two line of the brew output) – Riccardo Petraglia Oct 26 '16 at 21:02
  • You can try with ATLAS, mkl are not free... I do not know if you have them... (moreover you should then use the intel compiler) – Riccardo Petraglia Oct 26 '16 at 21:04
  • Line 421 looks like this `lintclean: @ $(RM) -r $(LINT_OUTPUT_DIR) $(EMPTY_LINT_REPORT) $(NONEMPTY_LINT_REPORT) ` That doesn't seem right. Can you be more specific about where I am adding it? – Melanie Oct 26 '16 at 21:04
  • 1
    At the end of this one... `LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) $(PKG_CONFIG) \ $(foreach library,$(LIBRARIES),-l$(library))` (sorry I was looking at the development version..). This is a long line broke in two.. – Riccardo Petraglia Oct 26 '16 at 21:06
  • So now that line looks as follows: `LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) $(PKG_CONFIG) \ $(foreach library,$(LIBRARIES),-l$(library)) \ -I/usr/local/opt/openblas/include \ -L/usr/local/opt/openblas/lib` – Melanie Oct 26 '16 at 21:09
  • Looks fine... try to make clean and make (-j 4 should run faster) – Riccardo Petraglia Oct 26 '16 at 21:10
  • I got a warning but no error! Fully compiled. Thank you so so much! – Melanie Oct 26 '16 at 21:13