是否可以使用python编译C代码? [英] Is it possible to compile c code using python?

查看:107
本文介绍了是否可以使用python编译C代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想构建一个python程序,该程序将输入.c文件的路径作为输入,然后对其进行编译。

I want to build a python program that get as input a path to .c file and then it compile its.

如果出现以下情况,该程序将在屏幕上输出OK:

The program will output OK to the screen if the compilation is sucessful, and BAD otherwise.

我一直在尝试搜索它,但找不到任何内容。我也一直在尝试使用编译程序的参数在python中运行cmd,但是它没有用。

I'm been trying to google it, but could not find anything. I've been also trying to run cmd within python with an argument of the compiling program but it didn't work.

要澄清-我已经有一个非常我要运行的计算机中的特定编译器。我不希望python充当编译器。只需获取代码,在其上运行我的编译器,然后查看答案是什么。

To clarify - I've already got a very specific compiler in my machine which I want to run. I dont want python to act as a compiler. Just get a code, run my compiler over it, and see what's the answer.


  • 它应在具有python 2.4的Linux服务器上工作。 / li>
  • It should work on Linux server with python 2.4.

谢谢

推荐答案

为什么不?当然,您需要安装GCC(或llvm),以便进行编译。您可以只使用os.system或任何其他方式来调用外部程序。

Sure, why not? Of course, you'd need GCC installed (or llvm) so you have something to compile with. You can just use os.system, or any of the other ways for calling an external program.

当然,最好查看 SCons ,它已经可以解决此问题。

Of course, you're probably better off looking at something like SCons, which already exists to solve this problem.

加,要回答实际提出的问题,没有什么可以阻止您使用python编写编译器/汇编器/链接器的,它们就像其他任何程序一样。但是性能可能不会很好。

Plus, to answer the question actually asked, there's nothing that would prevent you from writing a compiler/assembler/linker in python, they're just programs like anything else. Performance probably wouldn't be very good though.

这篇关于是否可以使用python编译C代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆