簡體   English   中英

如何使用 Python.h 和 MinGW 在 Windows 10 上編譯調用 Python 方法的 C 文件

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

我需要編譯一個 C 程序,它使用Python.h從現有的 Python 文件調用 Python 方法。

所有這些都在帶有MinGW的 Windows 10 機器上。

由於我找不到關於我需要什么編譯命令的直接答案,我現在將發布對我有用的內容,希望它也能幫助其他人!

對我有用的命令如下:

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

解釋:

  • nameOfexe :
    您想要的 .exe 名稱,可以說是命令的結果
  • nameOfCFile.c :
    要編譯的 C 文件並保存對 Python 方法的調用
  • PathToPython\\include
    python\\include 文件夾的路徑,例如:C:\\Python_3_9_0\\include
  • PathToPython\\libs
    python\\libs 文件夾的路徑,例如:C:\\Python_3_9_0\\libs
  • -lpythonXX :
    指定要編譯哪些庫以使 python 工作,
    XX = 你的版本:python3.9.0 --> -lpython39

C-File 和 Python-File 都在我運行命令的同一個文件夾中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM