This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]