I'm having this issue where the GCC compiler seems to be failing when it comes to linking two object files I have together. Both object files foo1.cc and foo2.cc include classes from a header file called foo1.hh. In addition, the header file foo.hh has as an external declaration of an object instance that appears in foo1.cc.
It should be noted that the header file foo.hh will only be defined once between the two source files foo1.cc and foo2.cc.
When I compile the source files using the following command, everything seems to work:
g++ foo1.cc foo2.cc
The above command will produce an executable called a.out.
When I try to compile the source files into object files independently:
g++ -c foo1.cc
g++ -c foo2.cc
g++ -o foo1.o foo2.o
The GCC compiler complains that there are undefined references to functions in foo2.cc. These functions should be defined in foo1.cc; however, the linker doesn't recognize that.
I was wondering if there was a way to get around this issue with the GCC compiler.