Compiling a program the embeds python
Robin Munn
rmunn at pobox.com
Tue Apr 22 13:58:37 EDT 2003
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.
--
Robin Munn <rmunn at pobox.com>
http://www.rmunn.com/
PGP key ID: 0x6AFB6838 50FF 2478 CFFB 081A 8338 54F7 845D ACFD 6AFB 6838
More information about the Python-list
mailing list