有没有办法从python编译c/c++程序?

is there a way to compile a c/c++ program from python?

本文关键字:c++ 程序 编译 python 有没有      更新时间:2023-10-16

目前我正在编写一个python脚本,以以下方式编译C/c++ Linux内核:

subprocess.check_call(["make", "-j5"])
subprocess.check_call(["make", "-j5", "modules_install"])
subprocess.check_call(["make", "-j5", "install"])

使用这些方法,命令在shell中执行。所以我想知道是否有另一种方法来编译内核使用python构建库?

最终,python不是C/c++编译器,因此您需要将编译工作交付给外部程序(例如gcc)。因此,在python中没有办法完全地

注意这里python不生成任何shell(尽管make可能)。你可以尝试完全在python中重现make所做的事情(有一个用python编写的make版本),但老实说,这并不值得。无论如何,您都需要生成子进程——您不妨使用已经存在并且"经过验证"的工具。