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

Undefined symbols when declaring ones own allocator.


Hi,

I am "playing" with defining my own allocator and I get
undefined symbols.  Shouldn't the compiler generate the
missing member functions automatically?

Test case:
-----------------------------------------
#include <iostream>
#include <sstream>

using namespace std;

class my_allocator : public allocator<char> {
public:
  pointer allocate(size_type size, allocator<void>::const_pointer hint = 0)
  {
    return new char[size];
  }

  void deallocate(pointer p, size_type)
  {
    delete [] p;
  }
};

typedef basic_ostringstream<char, char_traits<char>, my_allocator> my_ostrstream;

int main(void)
{
  my_ostrstream oss;
  oss.write("This is a test\n", 15);
  cout << oss.str();
  return 0;
}
-----------------------------------------


Compile result:
-----------------------------------------
>g++-3.0 -v test.cc
Reading specs from /usr/local/gcc-3.0/lib/gcc-lib/i686-pc-linux-gnu/3.0/specs
Configured with: /usr/src/gcc/gcc-cvs-3.0/configure --prefix=/usr/local/gcc-3.0 --enable-shared --with-gnu-as --with-gnu-ld --enable-languages=c++
gcc version 3.0 20010423 (prerelease)
 /usr/local/gcc-3.0/lib/gcc-lib/i686-pc-linux-gnu/3.0/cc1plus -v -D__GNUC__=3 -D__GNUC_MINOR__=0 -D__GNUC_PATCHLEVEL__=0 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__STDC_HOSTED__=1 -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i686__ -D__tune_pentiumpro__ test.cc -D__GNUG__=3 -D_GNU_SOURCE -D__EXCEPTIONS -D__GXX_ABI_VERSION=100 -quiet -dumpbase test.cc -version -o /tmp/cc6H83ff.s
GNU CPP version 3.0 20010423 (prerelease) (cpplib) (i386 Linux/ELF)
GNU C++ version 3.0 20010423 (prerelease) (i686-pc-linux-gnu)
        compiled by GNU C version 3.0 20010423 (prerelease).
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/gcc-3.0/include/g++-v3
 /usr/local/gcc-3.0/include/g++-v3/i686-pc-linux-gnu
 /usr/local/include
 /usr/local/gcc-3.0/lib/gcc-lib/i686-pc-linux-gnu/3.0/include
 /usr/local/gcc-3.0/i686-pc-linux-gnu/include
 /usr/include
End of search list.
 as -V -Qy -o /tmp/ccqM2QSA.o /tmp/cc6H83ff.s
GNU assembler version 2.10.90 (i386-redhat-linux) using BFD version 2.10.0.18
 /usr/local/gcc-3.0/lib/gcc-lib/i686-pc-linux-gnu/3.0/collect2 -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o
/usr/local/gcc-3.0/lib/gcc-lib/i686-pc-linux-gnu/3.0/crtbegin.o -L/usr/local/gcc-3.0/lib/gcc-lib/i686-pc-linux-gnu/3.0 -L/usr/local/gcc-3.0/lib/gcc-lib/i686-pc-linux-gnu/3.0/../../.. -rpath /usr/local/gcc-3.0/lib: /tmp/ccqM2QSA.o -lstdc++ -lm -lgcc_s -lc -lgcc_s /usr/local/gcc-3.0/lib/gcc-lib/i686-pc-linux-gnu/3.0/crtend.o /usr/lib/crtn.o
/tmp/ccqM2QSA.o: In function `main':
/tmp/ccqM2QSA.o(.text+0x71): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, my_allocator>(std::basic_ostream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, my_allocator> const&)'
/tmp/ccqM2QSA.o(.gnu.linkonce.d._ZTVSt15basic_stringbufIcSt11char_traitsIcE12my_allocatorE+0x18): undefined reference to `std::basic_stringbuf<char, std::char_traits<char>, my_allocator>::seekoff(long, std::_Ios_Seekdir, std::_Ios_Openmode)'
/tmp/ccqM2QSA.o(.gnu.linkonce.d._ZTVSt15basic_stringbufIcSt11char_traitsIcE12my_allocatorE+0x1c): undefined reference to `std::basic_stringbuf<char, std::char_traits<char>, my_allocator>::seekpos(std::fpos<__mbstate_t>, std::_Ios_Openmode)'
/tmp/ccqM2QSA.o(.gnu.linkonce.d._ZTVSt15basic_stringbufIcSt11char_traitsIcE12my_allocatorE+0x34): undefined reference to `std::basic_stringbuf<char, std::char_traits<char>, my_allocator>::pbackfail(int)'
/tmp/ccqM2QSA.o(.gnu.linkonce.d._ZTVSt15basic_stringbufIcSt11char_traitsIcE12my_allocatorE+0x3c): undefined reference to `std::basic_stringbuf<char, std::char_traits<char>, my_allocator>::overflow(int)'
collect2: ld returned 1 exit status


I am not sure its a bug, but it seems so...

-- 
Carlo Wood <carlo@alinoe.com>


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