简体   繁体   English

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

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

Currently I'm coding a python script to compile a C/C++ Linux kernel in the following way: 目前,我正在以以下方式编写python脚本来编译C / C ++ Linux内核:

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

With these approach the commands are executed in the shell. 通过这些方法,命令在外壳中执行。 So I was wondering if there is another way to compile the kernel using python build in libraries? 所以我想知道是否还有另一种方法可以使用库中的python build来编译内核?

Ultimately, python isn't a C/C++ compiler, so you need to ship out the compiling to an external program (eg gcc ). 最终,python不是C / C ++编译器,因此您需要将编译内容交付给外部程序(例如gcc )。 So, there is no way to do this entirely in python. 因此,没有办法完全在python中做到这一点。

Note that here python doesn't spawn any shells (although make might). 请注意,这里python不会生成任何shell(尽管make可能)。 You could try to reproduce what make does entirely in python, ( there is a version of make written in python FWIW), but honestly, it's not worth it. 您可以尝试重现make完全用python完成的功能( 有一个用python FWIW 编写的make版本 ),但说实话,这是不值得的。 You need to spawn subprocesses anyway -- you might as well use the tools which are already in place and "tried and true". 无论如何,您都需要生成子流程-您最好使用已经到位并且“经过验证”的工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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