是否可以使用python编译C代码?

编程入门 行业动态 更新时间:2024-10-15 18:27:00
本文介绍了是否可以使用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代码?

本文发布于:2023-11-13 22:30:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585502.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可以使用   代码   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!