解决/usr/bin/ld: 找不到 -lboost_python-py38
编译caffe报错:
CXX tools/convert_annoset.cpp
CXX tools/test_net.cpp
CXX tools/caffe.cpp
CXX tools/train_net.cpp
CXX tools/convert_imageset.cpp
CXX examples/cpp_classification/classification.cpp
CXX examples/cifar10/convert_cifar_data.cpp
CXX examples/siamese/convert_mnist_siamese_data.cpp
CXX examples/ssd/ssd_detect.cpp
CXX examples/mnist/convert_mnist_data.cpp
CXX .build_release/src/caffe/proto/caffe.pb.cc
AR -o .build_release/lib/libcaffe-nv.a
LD -o .build_release/lib/libcaffe-nv.so.0.17.0
/usr/bin/ld: 找不到 -lboost_python-py38
/usr/bin/ld: 找不到 -lpython3.8m
collect2: error: ld returned 1 exit status
Makefile:600: recipe for target '.build_release/lib/libcaffe-nv.so.0.17.0' failed
make: *** [.build_release/lib/libcaffe-nv.so.0.17.0] Error 1
make all -j4
LD -o .build_release/lib/libcaffe-nv.so.0.17.0
/usr/bin/ld: 找不到 -lboost_python-py38
/usr/bin/ld: 找不到 -lpython3.8m
collect2: error: ld returned 1 exit status
Makefile:600: recipe for target '.build_release/lib/libcaffe-nv.so.0.17.0' failed
make: *** [.build_release/lib/libcaffe-nv.so.0.17.0] Error 1
ldd正常的caffe
ldd caffe |grep boost
libboost_system.so.1.65.1 => /usr/lib/x86_64-linux-gnu/libboost_system.so.1.65.1 (0x00007f4310532000)
libboost_filesystem.so.1.65.1 => /usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.65.1 (0x00007f430fa69000)
libboost_python-py27.so.1.65.1 => /usr/lib/x86_64-linux-gnu/libboost_python-py27.so.1.65.1 (0x00007f430f4a0000)
libboost_thread.so.1.65.1 => /usr/lib/x86_64-linux-gnu/libboost_thread.so.1.65.1 (0x00007f42ffa2a000)
可见,编译caffe的时候找错了boost_python库。
解决方案1:
export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH
不好使,还是一样
解决方案2:注释掉~/.bashrc conda
sudo vim ~/.bashrc
# >>> conda initialize >>>
#export PATH="/media/algo/data_1/software/anconda_install/bin:$PATH"
source ~/.bashrc
终端敲conda无反应代表关闭conda成功了。
然后继续make all -j4
就编译成功了
2022年10月28日15:02:27
在服务器编译caffe又遇到这个错误:
CXX examples/cpp_classification/classification.cpp
CXX examples/mnist/convert_mnist_data.cpp
AR -o .build_release/lib/libcaffe-nv.a
LD -o .build_release/lib/libcaffe-nv.so.0.17.0
/usr/bin/ld: cannot find -lboost_python-py37
/usr/bin/ld: cannot find -lpython3.7m
collect2: error: ld returned 1 exit status
Makefile:600: recipe for target '.build_release/lib/libcaffe-nv.so.0.17.0' failed
make: *** [.build_release/lib/libcaffe-nv.so.0.17.0] Error 1
这回没有conda环境,所以不是上面的问题。
对比没问题的Makefile,发现
python_version_full := $(wordlist 2,4,$(subst ., ,$(shell python --version 2>&1)))
python_version_major := $(word 1,${python_version_full})
python_version_minor := $(word 2,${python_version_full})
python_version_patch := $(word 3,${python_version_full})
ifeq ($(python_version_major), 3)
python_lib_suffix := m
endif
PYTHON_LIBRARIES ?= boost_python-py${python_version_major}${python_version_minor} python${python_version_major}.${python_version_minor}${python_lib_suffix} boost_regex
WARNINGS := -Wall -Wno-sign-compare
把上面注释掉,加上这句
PYTHON_LIBRARIES ?= boost_python python2.7
WARNINGS := -Wall -Wno-sign-compare
好记性不如烂键盘---点滴、积累、进步!