ho questo codice C:undefined reference to `PyString_FromString'
... [SNIP] ...
for(Node = Plugin.Head; Node != NULL; Node = Node->Next) {
//Create new python sub-interpreter
Node->Interpreter = Py_NewInterpreter();
if(Node->Interpreter == NULL) {
Die("Py_NewInterpreter() failed");
}
//Create path to plugins main source file
snprintf(Filename, FILENAME_MAX, "%s/main.py", Node->File);
//Convert filename to python string
PFilename = PyString_FromString(Filename);
if(PFilename == NULL) {
Die("PyString_FromString(%s) failed", Filename);
}
//Import plugin main source file
PModule = PyImport_Import(PFilename);
if(PModule == NULL) {
Die("PyImport_Import(%s) failed", Filename);
}
//Deallocate filename
Py_DECREF(PFilename);
//Get reference to onLoad function from module
PFunction = PyObject_GetAttrString(PModule, "onLoad");
if(PFunction == NULL) {
Die("PyObject_GetAttrString() failed");
}
}
... [SNIP] ...
che dà questo errore durante la compilazione:
/tmp/ccXNmyPy.o: In function `LoadPlugins':
/home/alex/Code/Scribe/Scribe.c:693: undefined reference to `PyString_FromString'
collect2: error: ld returned 1 exit status
Python.h è inclusa nella parte superiore del file di origine.
Sto compilando con:
gcc -funwind-tables -rdynamic -I /usr/include/python2.7/ -g -o Scribe Scribe.c -lcurses `python-config --cflags` `python-config --ldflags` -Wall
sto basando il codice sui documenti Python C-API, da qui:
http://docs.python.org/2/c-api/
In particolare:
http://docs.python.org/2/c-api/string.html?highlight=pystring_fromstring#PyString_FromString
Non ho idea del motivo per cui questo è accad pening, halp? = c
Altri riferimenti alle funzioni Python C-Api hanno questo problema o è solo questo per 'PyString_FromString'? – martineau
@martineau È solo PyString_FromString, con quella linea commentata compila bene. – Alex
Sembra un linker - non compilatore - errore. Non hai bisogno di un'opzione '-L/path/to/libs' in modo che possa trovare il codice oggetto per le funzioni Python C-Api? – martineau