LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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



Reply
 
Search this Thread
Old 10-21-2009, 06:31 AM   #1
famsinyi
LQ Newbie
 
Registered: Nov 2007
Posts: 25

Rep: Reputation: 0
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?
 
Old 10-21-2009, 07:20 AM   #2
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 138Reputation: 138
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
 
Old 10-21-2009, 07:28 AM   #3
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
'gcc' preprocessor by default outputs to STDOUT, so it's a matter of 'popen' and friends.
 
Old 10-21-2009, 01:13 PM   #4
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,241

Rep: Reputation: 189Reputation: 189
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
 
Old 10-21-2009, 03:05 PM   #5
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: Debian lenny, Slackware 12
Posts: 809

Rep: Reputation: 178Reputation: 178
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.
 
  


Reply

Tags
cpp, gcc


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] 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 11:47 AM.

Main Menu
Advertisement
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
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration