How to compile and link together object files in C++ using the same header file? -


i'm having issue gcc compiler seems failing when comes linking 2 object files have together. both object files foo1.cc , foo2.cc include classes header file called foo1.hh. in addition, header file foo.hh has external declaration of object instance appears in foo1.cc.

it should noted header file foo.hh defined once between 2 source files foo1.cc , foo2.cc.

when compile source files using following command, seems work:

g++ foo1.cc foo2.cc 

the above command produce executable called a.out.

when try compile source files object files independently:

g++ -c foo1.cc g++ -c foo2.cc g++ -o foo1.o foo2.o 

the gcc compiler complains there undefined references functions in foo2.cc. these functions should defined in foo1.cc; however, linker doesn't recognize that.

i wondering if there way around issue gcc compiler.

there no issue, you've got error in gcc syntax.

g++ -c foo1.cc g++ -c foo2.cc g++ -o foo foo1.o foo2.o 

the -o parameter accepts name of output file, in case, overwrite foo1.o result of linkage.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -