This is the mail archive of the gcc-bugs@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]

template-problem


Hello,

I got following linker-error when compiling the enclosed piece of
C++-code with

        g++ -v -o test2 test2.cc


> Reading specs from /home/egcs/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.90.13/specs
> gcc version egcs-2.90.13 971016 (gcc2-970802 experimental)
>  /home/egcs/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.90.13/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=90 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem(posix) -D__EXCEPTIONS
 -Di386 -Di586 -Asystem(unix) -Acpu(i386) -Amachine(i386) -D__i386__ -D__i586__ -Asystem(unix) -Acpu(i386) -Amachine(i386) test2.cc /tmp/cca32228.ii
> GNU CPP version egcs-2.90.13 971016 (gcc2-970802 experimental) (i386 Linux/ELF)
> #include "..." search starts here:
> #include <...> search starts here:
>  /home/egcs/include/g++
>  /usr/local/include
>  /home/egcs/i586-pc-linux-gnulibc1/include
>  /home/egcs/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.90.13/include
>  /usr/include
> End of search list.
>  /home/egcs/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.90.13/cc1plus /tmp/cca32228.ii -quiet -dumpbase test2.cc -version -o /tmp/cca32228.s
> GNU C++ version egcs-2.90.13 971016 (gcc2-970802 experimental) (i586-pc-linux-gnulibc1) compiled by GNU C version egcs-2.90.13 971016 (gcc2-970802 experimental).
> In file included from /home/egcs/include/g++/iostream.h:31,
>                  from /home/egcs/include/g++/fstream.h:30,
>                  from test2.cc:1:
> /home/egcs/include/g++/streambuf.h:394: warning: invalid type `void *' for default argument to `ios *'
> In file included from /home/egcs/include/g++/fstream.h:30,
>                  from test2.cc:1:
> /home/egcs/include/g++/iostream.h:50: warning: invalid type `void *' for default argument to `ostream *'
> /home/egcs/include/g++/iostream.h: In method `int ostream::opfx()':
> /home/egcs/include/g++/iostream.h:53: warning: implicit declaration of function `int _IO_flockfile(...)'
> /home/egcs/include/g++/iostream.h: In method `void ostream::osfx()':
> /home/egcs/include/g++/iostream.h:54: warning: implicit declaration of function `int _IO_funlockfile(...)'
> /home/egcs/include/g++/iostream.h: At top level:
> /home/egcs/include/g++/iostream.h:123: warning: invalid type `void *' for default argument to `ostream *'
> /home/egcs/include/g++/iostream.h:230: warning: invalid type `void *' for default argument to `ostream *'
>  as -V -Qy -o /tmp/cca322281.o /tmp/cca32228.s
> GNU assembler version 2.8.1 (i586-pc-linux-gnu), using BFD version linux-2.8.1.0.1
>  /home/egcs/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.90.13/ld -m elf_i386 -rpath /home/egcs/lib -dynamic-linker /lib/ld-linux.so.1 -o test2 /usr/lib/crt1.o /usr/lib/crti.o /home/egcs/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.90.13/crtbegin.o -L/home/
egcs/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.90.13 -L/home/egcs/i586-pc-linux-gnulibc1/lib -L/home/egcs/lib /tmp/cca322281.o -lstdc++ -lm -lgcc -lc -lgcc /home/egcs/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.90.13/crtend.o /usr/lib/crtn.o
> /tmp/cca322281.o: In function `B<int>::dump(void)':
> /tmp/cca322281.o(.B<int>::gnu.linkonce.t.dump(void)+0x13): undefined reference to `operator<<(ostream &, C<int> const &)'
> collect2: ld returned 1 exit status


The second line of linker-output seems to be of special interest:

> ... undefined reference to `operator<<(ostream &, C<int> const &)'
                                                    ^^^^^^^^^^^^^^

The first snapshot producing such errors was 'egcs-970929'.
It should be noted that the specs-file has been modified to link
against shared libstdc++ residing in a local directory:

>  ... egcs-2.90.13/ld -m elf_i386 -rpath /home/egcs/lib ...
                                   ^^^^^^^^^^^^^^^^^^^^^

'uname --all' produced

> Linux couch 2.0.30 #1 Mon Jul 21 06:01:20 MET DST 1997 i586


I hope this helps tracking down the error.


	Thomas Arend
	ta@couch.ping.de


---------------------------- cut here ---------------------------
#include <fstream.h>
#include <iostream.h>
#include <stdlib.h>


template<class T1>
class C
{
  public:

  friend ostream& operator<<( ostream& os, const C<T1>& c ) ;

  protected:

  T1 val ;
} ;

template<class T1>
ostream& operator<<( ostream& os, const C<T1>& c )
{
  os << c.val ;

  return(os) ;
}


template<class T>
class B
{
  public:

  void dump( void ) ;

  protected:

  C<T> val ;
} ;

template<class T>
void B<T>::dump( void )
{
  cout << this->val << endl ;
}


int main( void )
{
  B<int> ac ;

  ac.dump() ;

  return(EXIT_SUCCESS) ;
}
---------------------------- cut here ---------------------------



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