一个简单的Python SWIG错误问题

时间:2009-03-15 20:27:49

标签: python swig

我正在尝试使用swig运行Python来执行C / C ++。我正在运行教程here,'构建一个python模块'。当我打电话时

gcc -c example.c example_wrap.c -I /my_correct_path/python2.5

我收到错误:

my_correct_path/python2.5/pyport.h:761:2: error: #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
example_wrap.c: In function 'SWIG_Python_ConvertFunctionPtr':
example_wrap.c:2034: warning: initialization discards qualifiers from pointer target type
example_wrap.c: In function 'SWIG_Python_FixMethods':
example_wrap.c:3232: warning: initialization discards qualifiers from pointer target type

它确实创建了一个example.o文件,但它不起作用。我在使用python2.5而不是2.1,例如,这是一个问题吗?错误(其他一切只是一个'警告')说错误的平台。这是一台64位的机器;这是一个问题吗?我的gcc配置错误了吗?我如何通过这个?

更新:我仍然遇到问题。我如何实际实现这个“修复”?

3 个答案:

答案 0 :(得分:7)

我发现这个线程正在为64位centos上安装32位python的python readline时出现相同“LONGBIT”错误的答案。该链接没有直接的答案,所以我不得不进一步谷歌答案(对于经验丰富的Linux用户/开发者来说可能是直截了当的)。为了将来参考,解决方案是在CFLAGS环境变量中使用“-m32”强制32位。

bash-3.2$ easy_install readline
Searching for readline
Reading http://pypi.python.org/simple/readline/
Reading http://www.python.org/
Best match: readline 2.6.4
Downloading http://pypi.python.org/packages/source/r/readline/readline-2.6.4.tar.gz#md5=7568e8b78f383443ba57c9afec6f4285
Processing readline-2.6.4.tar.gz
Running readline-2.6.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-mqr9wH/readline-2.6.4/egg-dist-tmp-p3apfF
In file included from /usr/local/python2.6/include/python2.6/Python.h:58,
                 from Modules/readline.c:8:
/usr/local/python2.6/include/python2.6/pyport.h:685:2: error: #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
error: Setup script exited with error: command 'gcc' failed with exit status 1

然后我尝试使用CFLAGS = -m32:

bash-3.2$ CFLAGS=-m32 easy_install readline
Searching for readline
Reading http://pypi.python.org/simple/readline/
Reading http://www.python.org/
Best match: readline 2.6.4
Downloading http://pypi.python.org/packages/source/r/readline/readline-2.6.4.tar.gz#md5=7568e8b78f383443ba57c9afec6f4285
Processing readline-2.6.4.tar.gz
Running readline-2.6.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-uauVci/readline-2.6.4/egg-dist-tmp-YY0tQa
In file included from /usr/include/features.h:352,
                 from /usr/include/limits.h:27,
                 from /usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/limits.h:122,
                 from /usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/syslimits.h:7,
                 from /usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/limits.h:11,
                 from /usr/local/python2.6/include/python2.6/Python.h:19,
                 from Modules/readline.c:8:
/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory
error: Setup script exited with error: command 'gcc' failed with exit status 1

最新的错误是由于没有32位的glibc-devel包(感谢this thread)。我还必须安装ncurses-devel.i386然后easy_install经过并且ipython认出了它。直到我为了ipython而工作,我的生活才被毁了。

bash-3.2$ CFLAGS=-m32 easy_install readline
Searching for readline
Reading http://pypi.python.org/simple/readline/
Reading http://www.python.org/
Best match: readline 2.6.4
Downloading http://pypi.python.org/packages/source/r/readline/readline-2.6.4.tar.gz#md5=7568e8b78f383443ba57c9afec6f4285
Processing readline-2.6.4.tar.gz
Running readline-2.6.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-dHly4D/readline-2.6.4/egg-dist-tmp-oIEDYl
Adding readline 2.6.4 to easy-install.pth file

Installed /home/hari/bin/python/lib/python2.6/site-packages/readline-2.6.4-py2.6-linux-x86_64.egg
Processing dependencies for readline
Finished processing dependencies for readline

答案 1 :(得分:2)

我在尝试安装Python软件包时遇到了同样的错误,但修复了它 “LONG_BIT”错误是:

$ easy_install astropy  
/my_path/epd/epd-7.3-2-rh5-x86/include/python2.7/pyport.h:849:2: 
error: #error "LONG_BIT definition appears wrong for platform 
(bad gcc/glibc config?)." error: Setup script exited with error: 
command 'gcc' failed with exit status 1

正如你所建议的那样,Alex,我必须安装正确版本的Python的epd才能满足我的机器要求和我想要安装的软件包的要求。有并行版本的Python运行,我认为这是混乱和错误的来源。转到Enthought's Repository(单击“登录存储库” - >安装程序)并安装正确的版本。

通过删除旧的Python版本,确保清理(或询问知道他们正在做什么的人为您做这件事)。然后当然更改.cshrc路径以指向新版本并正确地获取文件。我这样做后没有问题。

我意识到4年前就提出了这个问题!

答案 2 :(得分:2)

在尝试从源代码安装libxml2时,我实际上发现了这个线程两次,相隔几年。库的configure脚本实际上有一个--without-python选项,我使用它而不是尝试修复错误。