如何从stdin编译代码? [英] How to compile code from stdin?

查看:245
本文介绍了如何从stdin编译代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码很简单:

  test $ cat test.cpp 

int main )
{
}

有一种方法可以编译代码

  

cat test.cpp | g ++ -

和一些变体,但没有生成可执行文件。






只是一些澄清。我有一个程序,它预处理一个文件,并产生另一个文件,我想编译。我想不要创建这个中间文件,而是直接生成对象文件。

解决方案

编译器可能会告诉你:

 当从标准输入输入时需要-E或-x 
pre>

尝试

  cat test.cpp | g ++ -x c ++  -  


The code is quite simple :

test$ cat test.cpp

int main()
{
}

Is there a way to compile the code that is coming from a standard output?

I have tried this :

cat test.cpp | g++ -

and some variations, but none produced executable.


Just some clarifications. I have a program which preprocess a file, and produces another file which I want to compile. I thought about not creating this intermediate file, but to instead produce the object file directly.

解决方案

The compiler would have probably told you:

-E or -x required when input is from standard input

Try

cat test.cpp | g++ -x c++ -

这篇关于如何从stdin编译代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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