undefined references when i try to link a .cc file which contains classes

LLeweLLyn Reese llewelly@lifesupport.shutdown.com
Thu Jan 9 20:10:00 GMT 2003

Eilmsteiner Reinhard <r.eilmsteiner@paysafecard.com> writes:

> Hello Everybody!
> 1. I have a <class>.cc file which contains the implementation of a class
> 2. I have a <class>.h file that contains the associated header
> 3. I compile the <class>.cc file
> 4. I put the object file <class.o> into an archive lib<class>.a (ar rcs ...)
> 5. I compile the main program <prog>.cc
> 6. I try to link the things (g++ -lg++ -L. -l<class> -o <prog> <prog>.o)

g++ -lg++ -L. -o <prog> <prog>.o -l<class>

Link flags which specify libraries and object files are order
dependent. Put the .o file which calls the functions first, and the .o
or lib that defines the functions second. In some cases you may need
to refer to the same .o file more than once.

> 7. I get an "undefined references" error for each and every time i try to
> call any method within the class in the library from <prog>.
> 8. ******************* Why? *************************
> 9. Any ideas?

More information about the Gcc-help mailing list