python 安装 cffi 模块的一个问题

发布于 2024-04-25 16:24:17 字数 5067 浏览 58 评论 0

系统自带的 python 有点老(2.6)于是下载 python2.7.8 的源码手动编译安装(编译参数 ./configure --enable-shared --disable-ipv6 --prefix=/usr/local/python27 --enable-unicode=ucs4 )。

安装后将系统的 python 替换 ln -svf /usr/local/python27/bin/* /usr/bin/ ,安装 easy_install 和 pip( easy_install pip ),之后开始安装 pyopenssl,但是在安装依赖 cffi 的时候报错 /usr/bin/ld: cannot find -lpython2.7 ​。

首先需要说明的是出现类似**/usr/bin/ld: cannot find -lxx**的原因主要是 gcc 没有找到 libxx.so 的文件。

[root@ubox ~]# echo '/usr/local/python27/lib' > /etc/ld.so.conf.d/python-2.7.8.conf
[root@ubox ~]# ldconfig -v

ldconfig 命令为重建动态链接库的缓存,然后重新执行 pip install cffi , 但是还是报错,使用 gcc -lpython2.7 --verbose 查看 gcc 查找库的路径

[root@ubox lib]# gcc -lpython2.7 --verbose
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/:/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:/usr/lib/gcc/x86_64-redhat-linux/:/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:/usr/lib/gcc/x86_64-redhat-linux/
LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-mtune=generic'
/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/collect2 --eh-frame-hdr --build-id -m elf_x86_64 --hash-style=gnu -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.4.7/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7 -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7 -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../.. -lpython2.7 -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-redhat-linux/4.4.7/crtend.o /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crtn.o
/usr/bin/ld: cannot find -lpython2.7
collect2: ld returned 1 exit status

可以看到 /usr/local/python27/lib ​ 并不在上面的路径,google 一下找到了这个答案 http://stackoverflow.com/questions/8400272/usr-bin-ld-cannot-find-lpython2-7 , 然后:

[root@micaopan-dev lib]# locate libpython2.7.a
/usr/local/python27/lib/python2.7/config/libpython2.7.a
/usr/local/src/Python-2.7.8/libpython2.7.a
[root@micaopan-dev lib]# ln -s /usr/local/python27/lib/python2.7/config/libpython2.7.a /usr/lib
[root@micaopan-dev lib]# gcc -lpython2.7 --verbose
...
(.text+0x20): undefined reference to 'main'
collect2: ld returned 1 exit status

这个 gcc 找到了动态链接库,报错根据 http://stackoverflow.com/questions/15905119/c-linking-error-undefined-reference-to-main 应该并没有什么大碍。

然后执行 pip install cffi 成功。

参考

  1. /usr/bin/ld: cannot find -l* 错误的解决方法……
  2. 关于 usr/bin/ld: cannot find -lxxx 问题总结
  3. /usr/bin/ld: cannot find -lpython2.7
  4. C Linking Error: undefined reference to 'main'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

关于作者

软的没边

暂无简介

文章
评论
26 人气
更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文