LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 05: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, 06:20 AM   #2
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
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, 06:28 AM   #3
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

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

Rep: Reputation: 231Reputation: 231Reputation: 231
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, 02:05 PM   #5
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
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



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 10:25 AM
gcc-cpp problems (Mandrake 10.1) fatenabu Linux - Software 0 07-27-2005 01:42 PM
problem with cpp and gcc limboonlee Debian 2 04-25-2005 12:19 PM
How to programmatically break into gdb from gcc C++ source cj12345 Programming 7 09-16-2004 05:15 AM
Now I have gcc/cpp/cpp, but still can't install sfingerh Linux - Software 2 07-30-2002 03:13 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:13 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
Open Source Consulting | Domain Registration