Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 178096 - dev-lang/python - python-config returns bad compiler flags (included workaroud)
Summary: dev-lang/python - python-config returns bad compiler flags (included workaroud)
Status: RESOLVED DUPLICATE of bug 188029
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: x86 Linux
: High minor (vote)
Assignee: Python Gentoo Team
URL: http://venus.wsb-nlu.edu.pl/~kwalo/em...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-05-11 19:37 UTC by Krzysztof Walo
Modified: 2007-08-08 08:35 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Krzysztof Walo 2007-05-11 19:37:28 UTC
When I try to embed python code in C, I compile it, using command:
gcc -o embed_python $(python-config) embed_python.c

However python-config returns bad compiler flags and linker fails to build executable.

I've managed to create a workaround (see Additional Information).

Reproducible: Always

Steps to Reproduce:
1.Copy this C source to a file embed_python.c
#include <stdio.h>
#include <python2.4/Python.h>
int
main(int argc, char **argv) {
        Py_Initialize();
        PyRun_SimpleString("print 'Hello World!'");
        Py_Finalize();

        return 0;
}
2.Try to compile it, using:
gcc -o embed_python $(python-config) embed_python.c

3.Optionally, get my sample programs from
http://venus.wsb-nlu.edu.pl/~kwalo/embed_python.tar.gz
unpack it and type `make'. It shouldn't compile, by default :)

Actual Results:  
I get this output from python-config command:
-lpython2.4 -lm -L/usr/lib/python2.4/config

Additionally, python throws this Exception:
Traceback (most recent call last):
  File "/usr/bin/python-config-2.4.orig", line 3, in ?
    print "-lpython2.4 -lm -L/usr/lib/python2.4/config",string.join(string.split(distutils.sysconfig.get_config_var("MODLIBS")))
  File "/usr/lib/python2.4/string.py", line 292, in split
    return s.split(sep, maxsplit)
AttributeError: 'NoneType' object has no attribute 'split'

Such flags passed to compiler, cause liker not to build executable.
Output from the compiler:
/tmp/ccYDv0yc.o: In function `main':
bug_demo.c:(.text+0x12): undefined reference to `Py_Initialize'
bug_demo.c:(.text+0x1e): undefined reference to `PyRun_SimpleString'
bug_demo.c:(.text+0x23): undefined reference to `Py_Finalize'
collect2: ld returned 1 exit status

Expected Results:  
Output of python-config command, should return proper gcc flags. In my case, these are:
-lpython2.4 -lm

Running for example:
gcc -o embed_python $(python-config) embed_python.c
should create an executable.

I fixed this problem, by replacing contents of /usr/bin/python-config-2.4, with the following file:

#!/usr/bin/python
print "-lpython2.4 -lm"


With these flags, my sample C program compiles correctly.
Comment 1 Jakub Moc (RETIRED) gentoo-dev 2007-08-08 08:35:33 UTC

*** This bug has been marked as a duplicate of bug 188029 ***