Search code examples
pythonpython-3.xlinuxopencvcaffe

'make all' error when installing Caffe on Ubuntu 20.04 with OpenCV 4.2.0 for Python3: /usr/bin/ld cannot find lpython3.6m or lboost python3


I'm following this article to install caffe: https://qengineering.eu/install-caffe-on-ubuntu-18.04-with-opencv-4.2.html and get this error after running make all with libboost-all-dev and libpython3 already installed.

LD -o .build_release/lib/libcaffe.so.1.0.0
/usr/bin/ld: cannot find -lboost_python3
/usr/bin/ld: cannot find -lpython3.6m
collect2: error: ld returned 1 exit status
make: *** [Makefile:596: .build_release/lib/libcaffe.so.1.0.0] Error 1

I have a feeling I may need to create a soft link for the files into path or append to my PATH, LIBRARY_PATH, or LD_LIBRARY_PATH, but I'm not actually able to locate the libpython.so or libboost files, so I'm not sure how that would be done.


Solution

  • First check the exact version of python that python3 is pointing to and also whether you have python3.6m

    python3 -V 
    
    python3.6m -V
    

    Both should return you Python 3.6m, otherwise find out exact version of python that is installed or version of python you want to use, accordingly change it in Makefile.

    # say it's python3.7
    PYTHON_LIBRARIES ?= boost_python3 python3.7
    

    Locate libboost:

    locate boost | fgrep .so
    

    If libboost-all-dev is installed, located path will be either /usr/lib/x86_64-linux-gnu/ or /usr/lib64/ or /usr/lib/ or /usr/local/lib/ or some thing like this.

    Then depending upon path you get (say you get /usr/lib/), look for exact libboost.so :

    ls /usr/lib/libboost_python*.so
    

    If return list includes libboost_python3.so, check whether LD_LIBRARY_PATH includes path to that (path here for ex: /usr/lib), otherwise do:

    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/libboost/
    

    You can add it to your ~/.bashrc:

    echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/libboost/' >> ~/.bashrc
    

    If LD_LIBRARY_PATH includes path to .so for libboost, but name is different, say it's libboost_python-py37.so, accordingly change in Makefile.

    # say it's python3.7
    PYTHON_LIBRARIES ?= boost_python-py37 python3.7
    

    Then do:

    make all