构建静态库时SWIG Python2.7警告导致分段错误

时间:2015-08-20 06:01:29

标签: python c segmentation-fault makefile swig

我正在尝试使用swig构建一个静态库,以便在我的Python程序中使用C函数。我以前编译了swig命令和其他gcc编译步骤,我使用的是Python2.4.3。 Makefile的内容  是:

all:
 swig -python modlzo.i
 gcc -c -fPIC modlzo.c modlzo_wrap.c -I/usr/include/python2.4 -I/usr/local/include/
 gcc -shared -fPIC -o _modlzo.so  modlzo.o modlzo_wrap.o /usr/local/lib/liblzo.a -Wl,--whole-archive -Wl,--no-whole-archive

这个工作正常,我的python程序的make和c包装器。

现在我安装了另一个版本的python,即Python2.7.9。所以我将Makefile的内容更改为:

all:
swig -python modlzo.i
gcc -c -fPIC modlzo.c modlzo_wrap.c -I/usr/local/include/python2.7 -I/usr/local/include/
gcc -shared -fPIC -o _modlzo.so  modlzo.o modlzo_wrap.o /usr/local/lib/liblzo.a -Wl,--whole-archive -Wl,--no-whole-archive

现在当我尝试编译它时,我得到以下警告消息,当我在Makefile中使用Python2.4.3路径时,这些消息不存在:

modlzo_wrap.c: In function ‘SWIG_Python_ConvertFunctionPtr’:
modlzo_wrap.c:2034: warning: initialization discards qualifiers from pointer target type``
modlzo_wrap.c: In function ‘SWIG_AsCharPtrAndSize’:
modlzo_wrap.c:2691: warning: passing argument 3 of ‘PyString_AsStringAndSize’ from incompatible pointer type
modlzo_wrap.c: In function ‘SWIG_Python_FixMethods’:
modlzo_wrap.c:3642: warning: initialization discards qualifiers from pointer target type

这导致我运行python代码时出现分段错误。

知道为什么会发生这种情况以及可以采取哪些措施来解决这个问题?

0 个答案:

没有答案