Compiling a program the embeds python

Ben Lamb news03 at zurgy.org
Tue Apr 22 14:36:50 EDT 2003


Thanks very much for your reply which solved the problem. My logic and gcc's
are clearly at odds. As the for man page, I'm being shortchanged, mine only
has 2135 lines. I'll get the full docs.

Thanks again,

Ben.

Robin Munn wrote:

> Ben Lamb <news03 at zurgy.org> wrote:
>> 
>> I'm trying to compile an example program written in C that embeds Python.
>> The porgram is:
>> 
> [snip]
>> 
>> I use the following to compile it:
>> 
>> ben at localhost:~/prog/pyembed$ gcc -I/usr/local/include/python2.2
>> -L/usr/local/lib/python2.2/config -Xlinker -export-dynamic -lm
>> -lpython2.2 -ldl -lpthread -lutil pyembed.c
>> 
> [snip]
>> 
>> Please can someone point out what I am doing wrong.
> 
> The -l options, which specify which libraries to link against, need to
> come *after* the file(s) that need those libraries. Yes, this breaks the
> Unix rule-of-thumb that options always come first, and parameters
> second. Your command line should be:
> 
>     ben at localhost:~/prog/pyembed$ gcc -I/usr/local/include/python2.2
>     -L/usr/local/lib/python2.2/config -Xlinker -export-dynamic pyembed.c
>     -lm -lpython2.2 -ldl -lpthread -lutil
> 
> Check the gcc manpage, and read the section that describes the -l
> command. On my system, it starts at line 3630 of the manpage. You'll
> find the following paragraph:
> 
>     It makes a difference where in the command you write this option;
>     the linker searches and processes libraries and object files in the
>     order they are specified.  Thus, foo.o -lz bar.o searches library z
>     after file foo.o but before bar.o.  If bar.o refers to functions in
>     z, those functions may not be loaded.
> 
> Hope this helps.
> 

-- 
news.dsl.pipex.com




More information about the Python-list mailing list