`
Taoo
  • 浏览: 290898 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

python安装是 -fPIC问题的解决

阅读更多
尼玛真是头疼。


在安装好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 楼 白Rime 2017-12-27  
楼主在吗,我在装 libxml2 时,出现该问题,有些地方还是不懂,想问一下
13 楼 yeelor 2017-09-21  
$./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
12 楼 yeelor 2017-09-21  
$./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
11 楼 fuzzball 2016-04-27  
bo_hai 写道
楼主的办法解决我了的问题。给你32个


兄弟有QQ么,我也遇到了类似的问题还没解决,能否帮一把
10 楼 fuzzball 2016-04-27  
silent1 写道
编译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



我是弱鸡~~请问下这个脚本是在哪个地方执行
9 楼 bo_hai 2016-03-07  
楼主的办法解决我了的问题。给你32个
8 楼 bo_hai 2016-03-07  
bo_hai 写道
         

点错啦。
7 楼 bo_hai 2016-03-07  
        
6 楼 bo_hai 2016-03-07  
         
5 楼 linlinhust 2016-01-26  
多谢楼主,重新编译后解决了。
小贴士:编译的时候用make -j,多核cpu全开,非常快,不过内存占用高
4 楼 silent1 2015-04-22  
编译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
3 楼 iefsou 2014-11-07  
编译安装 libxml2 时,出现该问题,按楼主方法,将 python 重新编译后,解决了,非常感谢。
2 楼 iefsou 2014-11-07  
非常感谢。
1 楼 ttdeye 2013-09-10  
非常感谢,成功了!

相关推荐

Global site tag (gtag.js) - Google Analytics