Newbie - C API Question

Adam Hupp hupp at cs.wisc.edu
Mon Apr 14 22:03:48 EDT 2003


On Mon, Apr 14, 2003 at 06:36:39PM -0700, Ian Pellew wrote:
> Hi;
> 
> This is my first attempt at getting to and from my C world.
> 
> I cannot get past Python Reference Manual(2.2.1) section 1.2.1.1 :-
> 
> h.c:-
> #include "Python.h"
> main() {
>     int x;
>     PyObject *t;
>     t = PyTuple_New(3);
>     x = Py_file_input;
>     printf("Hiya, x = %d\n", x);
> }   
> 
> My compile gives:-
> [ `gcc -I/usr/local/include/python2.1 -o h h.c` ] && { ./h; }
> Undefined           first referenced
>  symbol                 in file
> PyList_New                          /var/tmp//ccNWkGt5.o
> ld: fatal: Symbol referencing errors. No output written to h
> collect2: ld returned 1 exit status
> 
> I am on Sun Solaris 5.8 
> Python 2.1.1 (#1, Aug 25 2001, 04:19:08) 
> [GCC 3.0.1] on sunos5
> 
> Any pointers/advice please;

You need to link against the python library.  Add '-lpython2.1
-L/usr/local/lib' to the gcc command line.  You may need to alter that
a bit, I'm just guessing.  Additionally, you will need to call
Py_Initialize() before making almost any Python API call.  Try the
Extending and Embedding docs, they will be more useful than the
reference manual.  http://www.python.org/doc/2.1.1/ext/ext.html

-Adam





More information about the Python-list mailing list