'make all' error: /usr/bin/ld cannot find lpython3.6m or lboost_python3

994 views
Skip to first unread message

Noah Baijo

unread,
Jul 24, 2020, 11:49:43 AM7/24/20
to Caffe Users
Installing Caffe with OpenCV 4.2.0 on Ubuntu 20, and received this error message after running 'make all' even though I have libboost-all-dev and libpython3 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  

My Makefile.config contains:

PYTHON_LIBRARIES := boost_python3 python3.6m
PYTHON_INCLUDE := /usr/include/python3.6m \
                 /usr/lib/python3/dist-packages/numpy/core/include
PYTHON_LIB := /usr/lib
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial/

I had a feeling I needed to set PATH, LIBRARY_PATH, or LD_LIBRARY_PATH to see these files or soft-link them in existing paths, but I can't even find where these files are located to do so.

Any help would be very much appreciated, thanks!

Tamas Nemes

unread,
Jul 24, 2020, 3:34:52 PM7/24/20
to Caffe Users
These are some common errors, also if it's not always clear where they come from. Check the following points:

1.  Go to /usr/lib/x86_64-linux-gnu and search for libboost_python. You are looking for libboost_python3-py36.so. In order for Caffe to find it, you should create a symlink with the name libboost_python3.so.
$ sudo ln -s libboost_python3-py36.so libboost_python3.so

2. Go to the Makefile and in line 218 (or just search for it), change to: PYTHON_LIBRARIES ?= boost_python python3.6

Normally, changing system-wide PATH and LD_LIBRARY_PATH is not necessary. Also, it strongly depends on which Caffe you want to build. If you want to use normal Caffe with OpenCV 4, I suggest trying the following guide in addition to my steps: https://qengineering.eu/install-caffe-on-ubuntu-18.04-with-opencv-4.1.html
With it, I was able to successfully compile on Ubuntu 20.04. I also send you my Makefile and .config-file  in order for you to look in it and maybe trying to use it as well.

Good luck!

Noah Baijo

unread,
Jul 27, 2020, 9:44:30 AM7/27/20
to Caffe Users
This fixed the libboost error, but the /usr/bin/ld cannot find lpython3.6m still remains an issue. Do you know how to fix this one too? If it helps, I'm using Python3.8.2 and installing caffe to use the CPU only, so no CUDA. Thank you very much for your help so far!

Tamas Nemes

unread,
Jul 27, 2020, 10:21:43 AM7/27/20
to Caffe Users
Then the problem should be obvious, right? You are using Python 3.8, but tell the compiler to search for Python 3.6 (which isn't even the default version in Ubuntu 20).
To fix, make these changes:

1. In the Makefile, in the same line as before: PYTHON_LIBRARIES ?= boost_python python3.8
2. In the Makefile.config, change to: PYTHON_LIBRARIES := boost_python3 python3.8
as well as: PYTHON_INCLUDE := /usr/include/python3.8 \

Don't forget adding this line to your .bashrc-file in the end of the process in order to make Caffe for Python work:
export PYTHONPATH="${PYTHONPATH}:/home/$USER/caffe-master/python" (or where your Caffe root folder is)

Noah Baijo

unread,
Jul 27, 2020, 12:08:32 PM7/27/20
to Caffe Users
That solved it!

I kept trying that before, but would change the PYTHON_INCLUDE to .../python3.8m and would revert it back to 3.6 when that wouldn't work. Simple mistake on my part.

Thank you very much for your help Tamas!

Tamas Nemes

unread,
Jul 27, 2020, 12:58:13 PM7/27/20
to Caffe Users
The Python versions 3.7 and up don't include the 'm' at the end anymore. You can simply have a look at the include and library files, then you can see which folders you specify exist.
Reply all
Reply to author
Forward
0 new messages