python 安装 cffi 模块的一个问题
系统自带的 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
成功。
参考
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论