Bypassing writing object file? (GCC, g++)

Hi I'm learning how to use GNU Compiler Collection to compile C++ projects.

Let's say I have a project with three source files:
main.cc
modulea.cc
modulea.hh

modulea defines a simple little std::cout function that is called from main().

I can build my executable like so:
1
2
$ g++ main.cc modulea.cc
$ ./a.out

and the result is a.out which I can execute.

I assume this is equivalent to creating an object file before compiling and using that:
1
2
3
$ g++ -c modulea.cc
$ g++ main.cc modulea.o
$ ./a.out

Same result, I get a.out.

Is the .o object file needed to help with using make to selectively re-compile only changed parts of the code?
Yes. make compares timestamps of sources and object files to decide which files to update.
As an aside, your terminology is a little confused - an object file is what you get when you compile. There's no way to bypass making an object file, only to avoid making it again if the source hasn't changed.
Last edited on
Thanks for the replies I think I understand more clearly now.

The reason I asked is because in the 1st example, there is no modulea.o file created that I can tell. Is it created temporarily and deleted once a.out is written?
Is it created temporarily and deleted once a.out is written?


KaBingo.
Topic archived. No new replies allowed.