1

I want to use a c program invoke a python program,

os:ubuntu 12.10 x64 python2.7.3

C code:

#include <stdio.h>
#include <stdlib.h>
#include <python2.7/Python.h>

int main(int argc, char** argv)
{
    printf("Hello world!\n");
    Py_Initialize();
    Py_SetProgramName("c_python");
    PyRun_SimpleString("print \"Hello world,Python!\"\n");
    Py_Finalize();
    exit(0);
}

compile shell:

gcc -I/usr/include/python2.7 -L/usr/lib/python2.7 -Wall -fPIC c_python.c -o c_pyton


/tmp/cciuHgrf.o:in ‘main’:
c_python.c:(.text+0x1c):reference undefined ‘Py_Initialize’
c_python.c:(.text+0x28):reference undefined ‘Py_SetProgramName’
c_python.c:(.text+0x3e):reference undefined ‘Py_Finalize’
collect2: error: ld return 1

1 Answer 1

2

You need to link the Python interpreter into your executable: -lpython.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.