views:

460

answers:

8

Is there a standalone C++ preprocessor? I don't need the compiler/linker, and I'm not able to install a full kit.

I'd like to be able to obtain preprocessed version of some headers, using some defines and include paths I provide.

EDIT: I can't rely on anything being available. No cl, no gcc, nothing. The least I would need done is something that processes macros ( specifically #ifdef and #if ).

EDIT: I'm using this on a Windows XP computer.

+4  A: 

Many compilers have a command-line option that will do what you want.

For example, GCC's is -E, and MSVC's is /P.

zildjohn01
All gcc does in invoke the correct application to do the work. gcc/g++ both use cpp on linux/unix environments.
Martin York
A: 

I suggest you to see C++ Template preprocessor tool.

Nathan Campos
I don't think that's what the OP is asking for.
jprete
+5  A: 

cpp is what you're looking for. I am not sure if it can be gotten outside of gcc distribution, though

CPP(1)                                                                 GNU                                                                 CPP(1)

NAME
       cpp - The C Preprocessor

SYNOPSIS
       cpp [-Dmacro[=defn]...] [-Umacro]
           [-Idir...] [-Wwarn...]
           [-M|-MM] [-MG] [-MF filename]
           [-MP] [-MQ target...]
           [-MT target...]
           [-P] [-fno-working-directory]
           [-x language] [-std=standard]
           infile outfile

Only the most useful options are listed here; see below for the remainder.

DESCRIPTION
       The C preprocessor, often known as cpp, is a macro processor that is used automatically by the C compiler to transform your program before
       compilation.  It is called a macro processor because it allows you to define macros, which are brief abbreviations for longer constructs.
Arkadiy
+1  A: 

Usually, the C++ compiler provides you with an option to see the preprocessed source.

With GCC, as was commented, you use:

g++ -E ...other options... files

On some systems, especially Unix systems, there may be a separate 'cpp' program. On MacOS X it installed as /usr/bin/cpp and is part of the GCC (GNU Compiler Collection).

Sometimes, it is installed in more out of the way places - on Solaris 10, it is /usr/lib/cpp, for example.

Jonathan Leffler
+2  A: 

I suppose you could try to build your own app using the standalone library, cpplib, but while they supply it, they don't recommend using it that way as it "has not yet reached a point of reasonable stability." I don't know how long that has been true.

Don Wakefield
+4  A: 

You might want to look at Boost Wave. It's a preprocessor built as a library instead of an application, but putting a wrapper around it to turn it into a standalone program should be fairly trivial (most of what you'd do is connect things up so it knows what file(s) to read from and write to).

Jerry Coffin
I'm fairly certain I've seen already seen such a wrapper, although I'm not entirely certain if that was part of the package.
MSalters
+4  A: 

You may want to have a look at GPP, Generic Pre Processor. It's customizable but it looks like it comes with some predefined setting which will do C/C++ preprocessing.

Edit: Looks like -C is the setting to use

-C cpp compatibility mode. This is the mode where gpp's behavior is the closest to that of >cpp. Unlike in the default mode, meta-macro expansion occurs only at the beginning of >lines, and C comments and strings are understood.

Graphics Noob
Does it work on windows?
Geo
A: 

http://mcpp.sourceforge.net/

mpp portable c preprocessor:

mcpp project was selected as one of the year 2002 "Exploratory Software Projects" at Information-Technology Promotion Agency, Japan (IPA), and selected again for the year 2003 projects. For the achievements of the project, the author was evaluated as one of the highest class programmers<<

Aftershock