Python Forum

Full Version: "Illegal variable name" message shown when trying to compile program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I am following this article to embed Python in C https://docs.python.org/3.7/extending/embedding.html
When I try to compile the program using the following command:
gcc -c $(/usr/local/python3.7-config) filename.c

it throws a message like this "Illegal variable name". Any help in this will be appreciated
Without the contents of filename.c, it is difficult to guess. Make sure the C code doesn't use C keywords as variable names.
(Apr-18-2019, 12:18 PM)Gribouillis Wrote: [ -> ]Without the contents of filename.c, it is difficult to guess. Make sure the C code doesn't use C keywords as variable names.

Well, the contents of filename.c

#define PY_SSIZE_T_CLEAN
#include <Python.h>

int
main(int argc, char *argv[])
{
wchar_t *program = Py_DecodeLocale(argv[0], NULL);
if (program == NULL) {
fprintf(stderr, "Fatal error: cannot decode argv[0]\n");
exit(1);
}
Py_SetProgramName(program); /* optional but recommended */
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print('Today is', ctime(time()))\n");
if (Py_FinalizeEx() < 0) {
exit(120);
}
PyMem_RawFree(program);
return 0;
}