Question
I have three files in my current working directory:
hello.cpp
goodbye.cpp
prog.cpp
I would like to only preprocess hello.cpp
and goodbye.cpp
and dump the output in files hello.i
and goodbye.i
. Is there a way to achieve this using g++
in a Ubuntu Linux command line using one command? The reason I would like to call g++
only once is because I would eventually like to include this command in my own Makefile.
What I've tried
I basically did the following:
g++ -E -o goodbye.i hello.i goodbye.cpp hello.cpp
Which, unsurprisingly, failed with the following error:
g++ : fatal error: cannot specify '-o' with '-c', '-S' or '-E' with multiple files compilation terminated
I also tried g++ -E goodbye.cpp hello.cpp
, which only reminded me that the preprocessor dumps to stdout by default. I do, for the purposes of this exercise, need for g++
to dump the result into an actual *.i
file...
What I'm trying to avoid
From the comments, it seems to me that I can provide a further clarification. I'm trying to avoid having multiple commands in my Makefile, as each separate .cpp
file would generate a separate command:
all: preprocess_hello preprocess_goodbye
preprocess_hello:
g++ -E -o hello.i hello.cpp
preprocess_hello:
g++ -E -o goodbye.i goodbye.cpp
Obviously, this is not ideal, because every new file I add would require adding a new command and updating the all
target.