tags:

views:

585

answers:

2

I am trying to get Python running with swig to do C/C++. I am running the tutorial here, 'building a python module'. When I do the call

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

I get an error:

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

It actually does create an example.o file, but it doesn't work. I am using python2.5 not 2.1 as in the example, is this a problem? The error (everything else is just a 'warning') says something about wrong platform. This is a 64bit machine; is this a problem? Is my gcc configured wrong for my machine? How do I get past this?

UPDATE: I am still having problems. How do I actually implement this "fix"?

+1  A: 

I think Dirk has the answer for you: follow his link.

Charlie Martin
I agree, why put an answer as a comment? Maybe, as he said, he just googled it, but either way I couldn't find it.
Alex
Well, he's probably not enough of a point-whore to take credit for it. Whereas I am. ;-)
Charlie Martin
I'd hate to post a Google-it as an answer. I was hoping that the OP will probably close this question. Anyway, Charlie can always buy me a beet ;-)
dirkgently
Got root?heh heh.
Charlie Martin
D'oh! I must've been smoking.
dirkgently
Hell, I should pay you for the straight line.
Charlie Martin
+1  A: 

I found this thread looking for an answer for the same "LONGBIT" error while installing python readline for 32bit python on 64bit centos. The link doesn't have the direct answer, so I had to google further for the answer (which might be straight-forward for seasoned linux users/devs). For future reference, the solution is to force 32-bit by using "-m32" in CFLAGS environment variable.

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

I then tried with 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

The latest error is due to not having glibc-devel package for 32bit (thanks to this thread). I also had to install ncurses-devel.i386 and then easy_install went through and ipython recognized it. My life felt ruined until I got this working for the sake of 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
haridsv