LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Tags used in this thread
Popular LQ Tags ,

Reply
 
Thread Tools
Old 10-21-2009, 06:31 AM   #1
famsinyi
LQ Newbie
 
Registered: Nov 2007
Posts: 11
Thanked: 0
calling gcc cpp functionality programmatically


[Log in to get rid of this advertisement]
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?
linux famsinyi is offline  
Tag This Post ,
Reply With Quote
Old 10-21-2009, 07:20 AM   #2
JohnGraham
Member
 
Registered: Oct 2009
Posts: 62
Thanked: 12
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
linuxubuntu JohnGraham is online now     Reply With Quote
Thanked by:
Old 10-21-2009, 07:28 AM   #3
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 1,033
Thanked: 50
'gcc' preprocessor by default outputs to STDOUT, so it's a matter of 'popen' and friends.
linuxsuse Sergei Steshenko is offline     Reply With Quote
Thanked by:
Old 10-21-2009, 01:13 PM   #4
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: washington U.S.
Distribution: Damn Small Linux, KateOs, M$ Ickdows Vista, My own OS
Posts: 1,233
Thanked: 59
Quote:
Originally Posted by Sergei Steshenko View Post
'gcc' preprocessor by default outputs to STDOUT, so it's a matter of 'popen' and friends.
STDERR not STDOUT
windows_vista smeezekitty is offline     Reply With Quote
Thanked by:
Old 10-21-2009, 03:05 PM   #5
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: Slackware 12.1
Posts: 447
Thanked: 51
Quote:
Originally Posted by smeezekitty View Post
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.
linux wje_lq is offline     Reply With Quote
Thanked by:

Reply

Bookmarks


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using gcc compiler on a .cpp file mcgill Linux - Newbie 2 05-31-2008 11:25 AM
gcc-cpp problems (Mandrake 10.1) fatenabu Linux - Software 0 07-27-2005 02:42 PM
problem with cpp and gcc limboonlee Debian 2 04-25-2005 01:19 PM
How to programmatically break into gdb from gcc C++ source cj12345 Programming 7 09-16-2004 06:15 AM
Now I have gcc/cpp/cpp, but still can't install sfingerh Linux - Software 2 07-30-2002 04:13 AM


All times are GMT -5. The time now is 10:18 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration