Tuesday, May 26, 2015

Caffe incompatible with Boost 1.58.0

Boost 1.58.0 was released on April 17th, and it breaks compilation with Caffe on OSX (when the build reaches one of the "NVCC" steps, you get a string of errors starting with complaining about the absence of a semicolon, that look like this: /usr/local/include/boost/smart_ptr/detail/sp_counted_base_clang.hpp(27): error: expected a ";"

Googling landed me on this page which suggested an incompatibility with boost 1.58.0 (https://groups.google.com/forum/#!topic/caffe-users/fY2r6bO3_0w). However, the steps suggested in the solution (as of May 26th; it seems to have been updated since) didn't work for me. So this is what I did, and it's kindof sketchy but oh well...

[July 16th update: Ian Blenke put together a boost-1.57 brew and mentioned how to use it in the comments; it looks a lot easier and less sketchy to install, but if that does not work for you, read on...]

1) cd $(brew --prefix) (for me this cd's to /usr/local/).
2) cd Library/Formula
3) Make a backup of the files boost.rb and boost-python.rb
4) Replace the boost.rb file with the contents of https://raw.githubusercontent.com/Homebrew/homebrew/6fd6a9b6b2f56139a44dd689d30b7168ac13effb/Library/Formula/boost.rb
5) Replace the boost-python.rb file with the contents of https://raw.githubusercontent.com/Homebrew/homebrew/3141234b3473717e87f3958d4916fe0ada0baba9/Library/Formula/boost-python.rb

6) brew uninstall boost (this should uninstall the 1.58.0 version)
7) brew install boost (this should install 1.57.0 since you've replaced the rb files)

(Edit: You *may* have to do "brew link boost" after this - can't recall exactly. Also, Parang Saraf pointed out a "no rule to make target" error in the comments, which they solved with "make clean")

Also, I missed this guide the first time I went through the page, so I'm linking to it in case you did too: http://caffe.berkeleyvision.org/install_osx.html

19 comments:

  1. Thanks for the tip!

    Can't you install boost 1.55 with "brew install homebrew/versions/boost155"? I don't want to recompile, but it seems like that should have worked and would have been much cleaner.

    ReplyDelete
    Replies
    1. (Huh, it looks like my earlier response got lost. Recommenting)

      That was the first thing I tried. Unfortunately boost155 is a keg-only brew, meaning "brew link" did not work. My udnerstanding is that if something needs a keg-only brew, it will specifically look for it; there is no way to get a keg-only brew to masquerade as a regular brew. The keg-only brew seemed to have some files and folders missing compared to the regular boost brew, so copy-pasting didn't work (I tried).

      Delete
  2. Hi,

    I tried your solution but now I am getting the following error:

    No rule to make target `/usr/local/include/boost/smart_ptr/detail/sp_counted_base_clang.hpp', needed by `.build_release/cuda/src/caffe/layers/absval_layer.o'. Stop.

    Do you know how to move forward?

    Thanks

    ReplyDelete
    Replies
    1. Did you do "brew link boost" afterwards?

      Delete
    2. Actually doing a "make clean" afterwards solved the problem. Maybe you can add this to your post. Thanks for the quick response

      Delete
    3. Interesting, I don't recall that. Will do.

      Delete
    4. After installing boost(brew install boost) I followed this...

      brew unlink boost && brew link boost
      make clean
      make all
      make test
      make runtest
      make pycaffe

      cd to python(cd python) , run program there , it worked for me :)
      thanks for the post

      Delete
  3. Thank you, this worked for me!

    ReplyDelete
  4. I ran into this same issue compiling caffe with cuda. Here's my fix:

    brew tap ianblenke/taps
    brew install --build-from-source -vd ianblenke/taps/boost boost-python

    To make that, I found the previous boost 1.57 homebrew formula here: https://raw.githubusercontent.com/Homebrew/homebrew/ab47508f0491a0acbce51a60ffd8da87991fd82a/Library/Formula/boost.rb

    The sourceforge tarball url is broken, but Fedora is hosting a copy:
    http://pkgs.fedoraproject.org/repo/pkgs/boost/boost_1_57_0.tar.bz2/1be49befbdd9a5ce9def2983ba3e7b76/boost_1_57_0.tar.bz2

    Updating the formula with that url, you can find a working 1.57 formula here:
    https://github.com/ianblenke/homebrew-taps/blob/master/boost.rb

    This should save you some frustration.

    ReplyDelete
  5. I had the same error and I followed your instructions (both Shrikumar and Blenke), but I have the error:

    clang: warning: argument unused during compilation: '-pthread'
    ld: library not found for -lhdf5_hl
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make: *** [.build_release/lib/libcaffe.so] Error 1
    make: *** Waiting for unfinished jobs....

    Any idea on how can I solve it? Paths in Makefile.config seems to be correct.

    ReplyDelete
    Replies
    1. It looks like you're missing the hdf5 library. Have you installed that? (have you installed all the dependencies in: http://caffe.berkeleyvision.org/install_osx.html)

      Delete
  6. This comment has been removed by the author.

    ReplyDelete
  7. I tried to do the same.

    After
    brew install boost

    I am stuck at output
    ./b2 --prefix=/usr/local/Cellar/boost/1.57.0 --libdir=/usr/local/Cellar/boost/1.57.0/lib -d2 -j4 --layout=tagged --user-config=user-config.jam install threading=multi,single link=shared,static

    ReplyDelete
  8. Your way is definite wrong if you have already dived into the source of boost157.rb : ie. the formula uses sha1, while brew use sha256. And I confirm the latest version of boost doen't work with the same error.

    ReplyDelete
  9. Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more. cialde caffe

    ReplyDelete