简体   繁体   中英

How to compile a C-File that calls a Python-Method on Windows 10 with Python.h and MinGW

I needed to compile a C-Programm that uses the Python.h to call a Python-Method from an existing Python-File.

And all that on a Windows 10 machine with MinGW .

As I could not find a straight-up answer on what compile command I need, I will now post what works for me in the hope it helps others too!

The command that worked for me is as follows:

gcc -o nameOfexe nameOfCFile.c -I PathToPython\include -L PathToPython\libs  -lpythonXX

Explanation:

  • nameOfexe :
    the name you want for your .exe, so to speak the result of the command
  • nameOfCFile.c :
    the C-File you want to compile and holds the call to the Python-Method
  • PathToPython\\include :
    the path to your python\\include folder, example: C:\\Python_3_9_0\\include
  • PathToPython\\libs :
    the path to your python\\libs folder, example: C:\\Python_3_9_0\\libs
  • -lpythonXX :
    that specifies what lib to compile for python to work,
    XX = your version: python3.9.0 --> -lpython39

Both the C-File and the Python-File are in the same Folder I run the command in.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM