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

Nov 21, 2011 at 11:08am
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?
Nov 21, 2011 at 1:42pm
Yes. make compares timestamps of sources and object files to decide which files to update.
Nov 21, 2011 at 2:28pm
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 Nov 21, 2011 at 2:28pm
Nov 21, 2011 at 2:50pm
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?
Nov 21, 2011 at 4:22pm
Is it created temporarily and deleted once a.out is written?


KaBingo.
Topic archived. No new replies allowed.