Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile code from stdin? [duplicate]

Tags:

c++

linux

gcc

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.

like image 443
BЈовић Avatar asked Jul 30 '13 13:07

BЈовић


2 Answers

The compiler would have probably told you:

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

Try

cat test.cpp | g++ -x c++ -
like image 168
devnull Avatar answered Nov 13 '22 17:11

devnull


Did you try this ?

$ cat tst.cpp | g++ -x c++ -

I have just tried it under Cygwin and had no problem.

like image 33
Shlublu Avatar answered Nov 13 '22 18:11

Shlublu