ITeye博客

python安装是 -fPIC问题的解决

Taoo · 2013-03-09 21:52 · python · 编程语言 · Markdown

尼玛真是头疼。

在安装好numpy、scipy、theano后。 在python代码中,敲入:import theano,报错如下:


Problem occurred during compilation with the command line below:

g++ -shared -g -m64 -fPIC -I/usr/local/lib/python2.7/site-packages/numpy/cor
e/include -I/usr/local/include/python2.7 -o /root/.theano/compiledir_Linux-2
.6.18-308.el5-x86_64-with-redhat-5.8-Tikanga-x86_64-2.7.3-64/lazylinker_ext/
lazylinker_ext.so /root/.theano/compiledir_Linux-2.6.18-308.el5-x86_64-with-
redhat-5.8-Tikanga-x86_64-2.7.3-64/lazylinker_ext/mod.cpp -L/usr/local/lib -
lpython2.7

/usr/bin/ld: /usr/local/lib/libpython2.7.a(abstract.o): relocation R_X86_64_
32 against `a local symbol' can not be used when making a shared object; rec
ompile with -fPIC

/usr/local/lib/libpython2.7.a: could not read symbols: Bad value

collect2: ld returned 1 exit status

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "theano/__init__.py", line 55, in <module>

    from theano.compile import \

  File "theano/compile/__init__.py", line 5, in <module>

    from theano.compile.function_module import *

  File "theano/compile/function_module.py", line 18, in <module>

    import theano.compile.mode

  File "theano/compile/mode.py", line 11, in <module>

    import theano.gof.vm

  File "theano/gof/vm.py", line 486, in <module>

    import lazylinker_c

  File "theano/gof/lazylinker_c.py", line 89, in <module>

    preargs=args)

  File "theano/gof/cmodule.py", line 1829, in compile_str

    (status, compile_stderr.replace(b('\n'), b('. '))))

Exception: Compilation failed (return status=1): /usr/bin/ld: /usr/local/lib
/libpython2.7.a(abstract.o): relocation R_X86_64_32 against `a local symbol'
 can not be used when making a shared object; recompile with -fPIC. /usr/loc
al/lib/libpython2.7.a: could not read symbols: Bad value. collect2: ld retur
ned 1 exit status.

仔细分析错误代码之后,定位原因在于, python在编译时,libpython2.7.a库中的abstract.o模块的编译过程中,没有加上-fPIC;

按照网上的方法,各种在python编译过程中加上-fPIC参数,都没有解决; 最后仔细看make命令的输出结果,发现abstract.o模块根本就没有经过编译。 继续最终,发现Python的源码路径中Object下,abstract.c和abstract.o都存在,而且这个文件是下载python包是就已经编译好了的(生成了.o文件); 然后删除所有.o文件,然后重新make,在make,就有abstract.o的编译过程了。

尼玛,这个问题整整搞了我10个小时,不知道能不能完全解决。


尼玛,就知道没有那么容易,后来又报另外一个包需要重新编译。 然后我把Python源码目录中所有自带的.o文件删了,然后就ok啦。。。

安装命令如下:


./configure --prefix=/usr/local/  –enable-shared CFLAGS=-fPIC
make
make install

评论(14)

  1. #14 楼 · 白Rime · 2017-12-27 08:55

    楼主在吗,我在装 libxml2 时,出现该问题,有些地方还是不懂,想问一下 :D

  2. #13 楼 · yeelor · 2017-09-21 17:13

    $./configure --prefix=/usr/local/ –enable-shared CFLAGS=-fPIC configure: WARNING: you should use --build, --host, --target configure: WARNING: invalid host type: –enable-shared checking build system type... Invalid configuration –enable-shared': machine –enable' not recognized configure: error: /bin/sh ./config.sub –enable-shared failed

  3. #12 楼 · yeelor · 2017-09-21 17:19

    $./configure --prefix=/usr/local/ –enable-shared CFLAGS=-fPIC configure: WARNING: you should use --build, --host, --target configure: WARNING: invalid host type: –enable-shared checking build system type... Invalid configuration –enable-shared': machine –enable' not recognized configure: error: /bin/sh ./config.sub –enable-shared failed

  4. #11 楼 · fuzzball · 2016-04-27 17:19

    bo_hai writes:

    楼主的办法解决我了的问题。给你32个 :idea:

    兄弟有QQ么,我也遇到了类似的问题还没解决,能否帮一把 :)

  5. #10 楼 · fuzzball · 2016-04-27 17:18

    silent1 writes:

    编译ganglia的时候出现此问题,按楼主方法,将 python 重新编译后,解决了,非常感谢。赠送删除所有.o文件脚本一枚

    #!/bin/sh ohome=$1 olist=du -a $ohome |grep '\.o$'| awk '{print $2}' for loop in $olist do cd ${loop%/*} rm -f $loop done

    我是弱鸡~~请问下这个脚本是在哪个地方执行 :cry:

  6. #9 楼 · bo_hai · 2016-03-07 15:36

    楼主的办法解决我了的问题。给你32个 :idea:

  7. #8 楼 · bo_hai · 2016-03-07 15:36

    bo_hai writes:

    :?: :?: :?: :?: :?: :?: :?: :?: :?: :?:

    点错啦。

  8. #7 楼 · bo_hai · 2016-03-07 15:36

    :idea: :idea: :idea: :idea: :idea: :idea: :idea: :idea: :idea:

  9. #6 楼 · bo_hai · 2016-03-07 15:36

    :?: :?: :?: :?: :?: :?: :?: :?: :?: :?:

  10. #5 楼 · linlinhust · 2016-01-26 20:17

    多谢楼主,重新编译后解决了。 小贴士:编译的时候用make -j,多核cpu全开,非常快,不过内存占用高

  11. #4 楼 · silent1 · 2015-04-22 15:10

    编译ganglia的时候出现此问题,按楼主方法,将 python 重新编译后,解决了,非常感谢。赠送删除所有.o文件脚本一枚

    #!/bin/sh ohome=$1 olist=du -a $ohome |grep '\.o$'| awk '{print $2}' for loop in $olist do cd ${loop%/*} rm -f $loop done

  12. #3 楼 · iefsou · 2014-11-07 23:35

    编译安装 libxml2 时,出现该问题,按楼主方法,将 python 重新编译后,解决了,非常感谢。

  13. #2 楼 · iefsou · 2014-11-07 23:34

    非常感谢。

  14. #1 楼 · ttdeye · 2013-09-10 12:14

    非常感谢,成功了!

评论功能维护中,当前仅展示历史评论。