iammilind
iammilind

Reputation: 69988

How to preprocess individual source file with several #include files spread across in large project?

For getting a preprocessed output, following command is used:

g++ -E a.cpp > temp.cpp

If a.cpp has #include files not in the same folder, then we use:

g++ -I <directory> -E a.cpp > temp.cpp

Now, there are several .cpp file for which I want a preprocessed output.
Also a huge #include dependency for every .cpp file and the header file is spread in several different subdirectories; so following option is very cumbersome:

g++ -I <dir1> -I <dir2> -I <dir3> ... -E a.cpp > temp.cpp

Is there any simpler way (preferably without the use of Makefile) ?
(Assume that dir1, dir2, ... are under a single directory)

Upvotes: 2

Views: 223

Answers (2)

ugoren
ugoren

Reputation: 16441

You need the same set of -I for preprocessing and for compiling.

When you actually compile the code, you surely use some set of -I parameters (probably generated by a make file).
So just use the same (or compile, and copy&paste the -I parameters).

The only alternative I see is restructuring your header directories to be in a common directory (with sub-directories, using #include <subdir/header.h>).
But this is much more work (though it may be worth the effort).

Upvotes: 3

saurabh jindal
saurabh jindal

Reputation: 121

One way can be that you give the TOP directory in which all the subdirectory resides. This way you wont have to give many -I. But this will slowdown it.

Upvotes: 0

Related Questions