This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: undefined references when i try to link a .cc file which contains classes
- From: LLeweLLyn Reese <llewelly at lifesupport dot shutdown dot com>
- To: Eilmsteiner Reinhard <r dot eilmsteiner at paysafecard dot com>
- Cc: "'gcc-help at gcc dot gnu dot org'" <gcc-help at gcc dot gnu dot org>
- Date: 09 Jan 2003 12:07:42 -0800
- Subject: Re: undefined references when i try to link a .cc file which contains classes
- References: <23FD0445E7F1D4119D910002A50981138D189F@s-vie1-11.psc.com>
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?