/usr/bin/ld: cannot find -lpython2

本文记录了Caffe编译过程中遇到的问题及解决方法,特别是在构建Matlab接口时由于gcc版本不匹配导致的链接错误。通过调整CMake配置文件解决了-lpython2.7链接失败的问题。
Q:
$ make 
[  1%] Built target proto
[ 84%] Built target caffe
[ 85%] Built target caffe.bin
[ 87%] Built target compute_image_mean
[ 88%] Built target convert_imageset
[ 88%] Built target device_query
[ 90%] Built target extract_features
[ 90%] Built target finetune_net
[ 90%] Built target net_speed_benchmark
[ 90%] Built target test_net
[ 92%] Built target train_net
[ 92%] Built target upgrade_net_proto_binary
[ 93%] Built target upgrade_net_proto_text
[ 95%] Built target upgrade_solver_proto_text
[ 95%] Built target classification
[ 95%] Built target convert_cifar_data
[ 95%] Built target convert_mnist_data
[ 96%] Built target convert_mnist_siamese_data
[ 98%] Built target pycaffe
[ 98%] Building Matlab interface: /home/junmuzi/Works/my_works/lstm/caffe/matlab/+caffe/private/caffe_.mexa64
Building with 'g++'.
Warning: You are using gcc version '4.8.4'. The version of gcc is not supported. The version currently supported with MEX is '4.7.x'. For a list of currently supported compilers see: http://www.mathworks.com/support/compilers/current_release.
Warning: You are using gcc version '4.8.4-2ubuntu1~14.04)'. The version of gcc is not supported. The version currently supported with MEX is '4.7.x'. For a list of currently supported compilers see: http://www.mathworks.com/support/compilers/current_release.
/usr/bin/ld: cannot find -lpython2
collect2: error: ld returned 1 exit status


make[2]: *** [../matlab/+caffe/private/caffe_.mexa64] Error 255
make[1]: *** [matlab/CMakeFiles/matlab.dir/all] Error 2
make: *** [all] Error 2
----
Solution:
modify file matlab/CMakeFiles/matlab.dir/build.make, and delete "-lpython2.7"
Then, re-make, "# make"
在编译或链接程序时遇到 `/usr/bin/ld: cannot find -lpython3.6` 错误,通常表示链接器 `ld` 无法找到所需的 `libpython3.6.so` 库文件。造成该问题的原因可能包括库文件缺失、库文件版本不匹配、库路径未正确配置等。以下是几种常见的解决方法: ### 1. 安装缺失的 Python 开发库 如果系统中确实缺少 `libpython3.6.so`,可以通过安装对应的开发包来解决问题。例如,在基于 Debian 的系统(如 Ubuntu)上,可执行以下命令安装: ```bash sudo apt update sudo apt install libpython3.6-dev ``` 该操作将安装 Python 3.6 的开发文件,包括所需的链接库 `libpython3.6.so` [^3]。 ### 2. 创建软链接指向现有库文件 如果系统中已经存在 `libpython3.6.so` 的其他版本,例如 `libpython3.6.so.1.0` 或类似文件,可以通过创建软链接的方式将其重命名为 `libpython3.6.so`。例如: ```bash sudo ln -s /usr/lib/python3.6/config-3.6m-x86_64-linux-gnu/libpython3.6.so /usr/lib/libpython3.6.so ``` 此操作将链接器期望的库名与实际存在的库文件关联起来,从而解决找不到库的问题 [^1]。 ### 3. 检查并配置库搜索路径 如果库文件已存在但未被链接器识别,可能是因为其所在目录未包含在 `LD_LIBRARY_PATH` 或 `LIBRARY_PATH` 中。可以使用以下命令查看当前配置: ```bash echo ${LD_LIBRARY_PATH} echo ${LIBRARY_PATH} ``` 若库文件所在路径不在输出中,可通过以下命令临时添加路径: ```bash export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/path-to-your-lib export LIBRARY_PATH=${LIBRARY_PATH}:/path-to-your-lib ``` 此方法适用于库文件存在于非标准目录中的情况 [^4]。 ### 4. 验证库文件是否存在 在尝试上述方法前,建议先使用 `locate` 或 `find` 命令确认系统中是否存在 `libpython3.6.so` 或其变体: ```bash locate libpython3.6.so ``` 若输出中未找到相关文件,则需安装开发包或手动复制库文件 。 ### 示例:创建软链接并重新编译 假设通过 `locate` 发现 `libpython3.6.so` 存在于 `/usr/lib/python3.6/config-3.6m-x86_64-linux-gnu/` 目录下,可以执行以下操作: ```bash sudo ln -s /usr/lib/python3.6/config-3.6m-x86_64-linux-gnu/libpython3.6.so /usr/lib/libpython3.6.so make clean make -j ``` 此操作将修复链接器无法找到库的问题,并重新编译项目 。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值