LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   calling gcc cpp functionality programmatically (http://www.linuxquestions.org/questions/programming-9/calling-gcc-cpp-functionality-programmatically-763407/)

famsinyi 10-21-2009 06:31 AM

calling gcc cpp functionality programmatically
 
Hi,

Does anyone know how to call gcc cpp functionality in a program so that the preprocessed output is directed to a memory location rather than a file?

JohnGraham 10-21-2009 07:20 AM

The easiest way I can think of is to essentially call

Code:

system("gcc -E -o output.i input.c");
and then output.i and read the file into memory, or mmap it. This puts it in a file first, though... is that really disastrous?

John G

Sergei Steshenko 10-21-2009 07:28 AM

'gcc' preprocessor by default outputs to STDOUT, so it's a matter of 'popen' and friends.

smeezekitty 10-21-2009 01:13 PM

Quote:

Originally Posted by Sergei Steshenko (Post 3727129)
'gcc' preprocessor by default outputs to STDOUT, so it's a matter of 'popen' and friends.

STDERR not STDOUT

wje_lq 10-21-2009 03:05 PM

Quote:

Originally Posted by smeezekitty (Post 3727457)
STDERR not STDOUT

From the man page:
Code:

      -E  Stop after the preprocessing stage; do not run the compiler proper.
          The output is in the form of preprocessed source code, which is
          sent to the standard output.

          Input files which don't require preprocessing are ignored.



All times are GMT -5. The time now is 06:44 PM.