Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22133

How do I compile a C program which includes Python.h on Windows?

$
0
0

I am trying to learn how to embed a Python interpreter into my C/C++ programs.

I like this concept because it may enable me to extend C programs at run time as well as enable users to write custom scripts/plugins.

Detailed instruction on embedding Python in C is provided at: https://docs.python.org/3/extending/embedding.html

I'm using example code provided in the Python documentation to figure out the mechanics involved:

embedded.c

#include <Python.h>intmain(int argc, char *argv[]){  Py_SetProgramName(argv[0]);  /* optional but recommended */  Py_Initialize();  PyRun_SimpleString("from time import time,ctime\n""print 'Today is',ctime(time())\n");  Py_Finalize();  return 0;}

The problem is I can't figure out how to compile it on Windows using gcc.

C:\Users\user\embedded_python> gcc embedded.cembedded.c:2:10: fatal error: Python.h: No such file or directory #include <Python.h>          ^~~~~~~~~~compilation terminated.

I think the problem is I need to link to the Python.h file, but I can't seem to get the compiler flags right:

C:\Users\user\Desktop\embedded_python>gcc -IC:\Users\user\AppData\Local\Programs\Python\Python38 -lPython38 embedded.cembedded.c:2:10: fatal error: Python.h: No such file or directory #include <Python.h>          ^~~~~~~~~~compilation terminated.

How can I get this program to compile on Windows (preferably with gcc/g++ to avoid Visual Studio bloat)?


Viewing all articles
Browse latest Browse all 22133

Trending Articles