Python Forum
"Illegal variable name" message shown when trying to compile program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"Illegal variable name" message shown when trying to compile program
#1
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
Reply
#2
Without the contents of filename.c, it is difficult to guess. Make sure the C code doesn't use C keywords as variable names.
Reply
#3
(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;
}
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Illegal instruction (core dumped) when import pandas. amandacstr 1 2,106 Dec-31-2022, 11:31 PM
Last Post: stevendaprano
  Illegal instruction? working code for months? korenron 4 13,103 Aug-05-2021, 09:57 AM
Last Post: korenron
  ntlk error shown ErnestTBass 2 4,670 Oct-29-2020, 10:37 PM
Last Post: snippsat
  Python - change variable type during program execution ple 1 2,386 Apr-12-2020, 08:43 AM
Last Post: buran
  error message on program launch DJPY1175 0 1,746 Jun-10-2019, 08:40 AM
Last Post: DJPY1175
  'Illegal characters found in parameter 'quantity'; legal range is...' psh6615 4 9,334 Apr-19-2018, 04:13 PM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020