query regarding embeding python in C

Discussion in 'Python' started by Vardhman Jain, Apr 7, 2004.

  1. Hi,
    I am trying out the concept of python code being executed from a C
    program. I got a peice of code from the tutorial but I don't know how to
    compile/use it

    The code is
    #include <Python.h>

    int
    main(int argc, char *argv[])
    {
    Py_Initialize();
    PyRun_SimpleString("from time import time,ctime\n"
    "print 'Today is',ctime(time())\n");
    Py_Finalize();
    return 0;
    }
    ~
    ~


    Now If I do "c++ temp.c -I /usr/include/python2.2/" I get the errors
    [vardhman@linuxAddict TA]$ c++ temp.c -I /usr/include/python2.2/
    /tmp/ccnpr9em.o(.text+0x11): In function `main':
    : undefined reference to `Py_Initialize'
    /tmp/ccnpr9em.o(.text+0x1e): In function `main':
    : undefined reference to `PyRun_SimpleString'
    /tmp/ccnpr9em.o(.text+0x26): In function `main':
    : undefined reference to `Py_Finalize'
    collect2: ld returned 1 exit status

    Can some one tell me how to compile and use this code.


    Vardhman


    --
    Vardhman Jain
    III Year B.Tech. CSE
    IIIT-Hyderabad
    Address:
    Room No 27, NBH, IIIT-Hyderabad,Hyderabad 500019

    presence on net:
    http://students.iiit.net/~vardhman
    Vardhman Jain, Apr 7, 2004
    #1
    1. Advertising

  2. Looks like you may have forgotton to link with libpython.a...for
    example, if your system has Python 2.3 installed, add this to your
    compile/link line: -L/usr/lib/python2.3/config -lpython2.3


    Vardhman Jain wrote:
    > Hi,
    > I am trying out the concept of python code being executed from a C
    > program. I got a peice of code from the tutorial but I don't know how to
    > compile/use it
    >
    > The code is
    > #include <Python.h>
    >
    > int
    > main(int argc, char *argv[])
    > {
    > Py_Initialize();
    > PyRun_SimpleString("from time import time,ctime\n"
    > "print 'Today is',ctime(time())\n");
    > Py_Finalize();
    > return 0;
    > }
    > ~
    > ~
    >
    >
    > Now If I do "c++ temp.c -I /usr/include/python2.2/" I get the errors
    > [vardhman@linuxAddict TA]$ c++ temp.c -I /usr/include/python2.2/
    > /tmp/ccnpr9em.o(.text+0x11): In function `main':
    > : undefined reference to `Py_Initialize'
    > /tmp/ccnpr9em.o(.text+0x1e): In function `main':
    > : undefined reference to `PyRun_SimpleString'
    > /tmp/ccnpr9em.o(.text+0x26): In function `main':
    > : undefined reference to `Py_Finalize'
    > collect2: ld returned 1 exit status
    >
    > Can some one tell me how to compile and use this code.
    >
    >
    > Vardhman
    >
    >
    > --
    > Vardhman Jain
    > III Year B.Tech. CSE
    > IIIT-Hyderabad
    > Address:
    > Room No 27, NBH, IIIT-Hyderabad,Hyderabad 500019
    >
    > presence on net:
    > http://students.iiit.net/~vardhman
    >
    >
    >
    Rick L. Ratzel, Apr 8, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fabien SK

    Embeding Python, COM crash

    Fabien SK, Jul 30, 2003, in forum: Python
    Replies:
    0
    Views:
    315
    Fabien SK
    Jul 30, 2003
  2. kiokju

    Python embeding error!!

    kiokju, Jan 18, 2006, in forum: Python
    Replies:
    0
    Views:
    272
    kiokju
    Jan 18, 2006
  3. mani
    Replies:
    0
    Views:
    301
  4. mani
    Replies:
    1
    Views:
    462
  5. Hongtian

    How to debug embeding Python?

    Hongtian, Dec 30, 2008, in forum: Python
    Replies:
    4
    Views:
    329
    Hongtian
    Jan 1, 2009
Loading...

Share This Page