13

I'm trying to compile Caffe (http://caffe.berkeleyvision.org/installation.html) and I get the following errors:

/usr/bin/ld: cannot find -lcblas
/usr/bin/ld: cannot find -latlas

However, I have these libraries installed (libatlas). My LD_LIBRARY_PATH contains the path /usr/lib/atlas-base and it contains the files libcblas.so and libatlas.so (and some other files as well).

Why ld can't find these libraries? Thanks.

fvu
  • 32,488
  • 6
  • 61
  • 79
Ran
  • 4,117
  • 4
  • 44
  • 70

4 Answers4

11

tl;dr: Caffe makefile looks for libblas.so in /usr/lib. If missing, update-alternatives creates a symbolic link /usr/lib/libblas.so to the location where it is installed. Same applies to libcblas.so. LD_LIBRARY_PATH is for runtime, and doesn't have anything to do with this.


LD_LIBRARY_PATH doesn't really help you when compiling. It only provides directories to look for shared libraries when executing programs that rely on them, after they are compiled. Still, when linking during the compilation, the compiler needs to find these shared libraries, and does so by other means than LD_LIBRARY_PATH.

More to the point: if compiling with gcc or clang, the directories in which to look for libraries to link with are provided using the -L flag, and it does not consider the LD_LIBRARY_PATH environment variable.

Common locations for libblas.so are /usr/lib/atlas-base/ and /usr/lib/libblas/. The Makefile for caffe doesn't do anything particular to try and locate these subdirectories, and relies on these libraries being in the default library directory /usr/lib/. Typically a symbolic link /usr/lib/libblas.so exists, and points to the real location of the shared library. For some reason, this wasn't the case in your initial configuration.

When dealing with multiple alternatives for packages, update-alternatives comes in handy. In the case of libblas.so it let's you easily switch between multiple implementations (libblas, openblas) you might have installed, and does so by changing out the symbolic links.

sudo update-alternatives --config libblas.so created this symbolic link when it was missing, which in turn let the compiler find the shared library, solving your problem. This is indicated by the output of the command:

 $ sudo update-alternatives --config libblas.so
There is only one alternative in link group libblas.so (providing /usr/lib/libblas.so): /usr/lib/libblas/libblas.so
Nothing to configure.

Same kind of reasoning applies to libcblas.so.

swalog
  • 4,403
  • 3
  • 32
  • 60
6

It turns out I had to run

sudo update-alternatives --config libblas.so
sudo update-alternatives --config liblapack.so

and to select libatlas . I have no idea why,. If anyone can explain this me I will give him the answer. Thanks.

Ran
  • 4,117
  • 4
  • 44
  • 70
6

sudo apt-get install libatlas-base-dev worked for me, it removed both missing dependencies.

See this thread for additional details https://github.com/BVLC/caffe/issues/559

Mar Cnu
  • 1,165
  • 11
  • 16
4

As an addendum to @Ran's answer, Ubuntu in particular has an odd package structure for what's needed with Caffe. I just came across this post in fixing this same issue on my own machine, and here's some help if others are stuck. (Ubuntu 14.04).

libatlas-dev does NOT have libatlas-base-dev as a dependency! Caffe seems to like the libraries from the latter only. Install it.

Then, run the commands suggested by @Ran and select the libraries from the atlas-base directory under /usr/lib. With just libatlas-dev installed, update-alternatives will have the output at the bottom of @swalog's post, but does not actually link an atlas library that caffe seems to approve of! It needs to be the one from atlas-base. Hope this helps!