一个简单的Python SWIG错误问题

2024-06-02 08:05:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图让Python与Sigg一起运行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是否为我的机器配置错误?我该如何度过这个难关?

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


Tags: pathinexamplemy错误functionerrorswig
3条回答

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

在64位centos上安装32位python的python readline时,我发现这个线程正在寻找相同“LONGBIT”错误的答案。这个链接没有直接的答案,所以我不得不在google上搜索更多的答案(这对于经验丰富的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,然后简单的安装完成,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

我在尝试安装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年前提的!

相关问题 更多 >