Can I get GCC to read from a channel?

I'm looking for a gcc option that will make it read the source file from standard input, basically, so I could do something like this to create an object file from a tool like flex that generates C code ( flex -t writes the generated C to standard output):

 flex -t lexer.l | gcc -o lexer.o -magic-option-here 

because I really don't care about the generated C file.

Is there something like this, or do I need to use temporary files?

+60
gcc command-line flex-lexer pipe
Jun 16 '09 at 20:01
source share
2 answers

Yes, but you must specify the language using the -x option:

 # Specify input file as stdin, language as C flex -t lexer.l | gcc -o lexer.o -xc - 
+72
Jun 16 '09 at 20:03
source share
 flex -t lexer.l | gcc -xc -c -o lexer.o - 

Basically you say the file name is - - . Specifying a file name - a somewhat standard convention for the expression "standard input". You also need the -c flag so that you don't make links. And when the GCC reads from standard input, you have to tell it in which language it is -x . -xc says this is C code.

+18
Jun 16 '09 at 20:07
source share



All Articles