[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Link errors when deriving from iostream (Linux only)
From: |
James Kanze |
Subject: |
Link errors when deriving from iostream (Linux only) |
Date: |
Sat, 02 Apr 2005 14:28:45 +0200 |
User-agent: |
Mozilla Thunderbird 1.0 (X11/20041206) |
I have an object which derives from std::iostream.
When I try and link it, I get undefined symbols for the
destructor of iostream. Only under Linux, curiously, the exact
same code works under Solaris, so I suppose that it is either a
problem with my installation, or some flags that I missed that
are necessary under Linux, but not elsewhere.
FWIW:
- Whether the object file with my class is in a library or
specified directly doesn't seem to change anything.
- An nm -p -C on the object file with my class reveles a
number of U entries for std::iostream! This sort of
surprises me; I could almost understand
std::basic_iostream<char> (which is what I get when I
specify the template in full when deriving), although I
really don't know what to expect -- I was under the
impression that g++ instantiated the templates in every file
which used them.
I might add that if I change the code to derive from just
std::istream (instead of std::iostream), I still get U
entries for std::istream, but the code links and works as
expected. So I don't know what to think.
Anyway, does anyone know of any options which might affect this,
either when building the compiler, or when compiling. Or is
this a compiler bug, which just shows up on certain systems?
(Just for the record: a minimal example :
---------- MyClass.hh ------------
#ifndef GB_MyClass_hh
#define GB_MyClass_hh
#include <istream>
#include <ostream>
struct MyClass : public std::iostream
{
MyClass() ;
~MyClass() ;
} ;
#endif
---------- MyClass.cc ------------
#include "MyClass.hh"
MyClass::MyClass()
{
}
MyClass::~MyClass()
{
}
---------- main.cc ------------
#include "MyClass.hh"
int
main()
{
MyClass c ;
return 0 ;
}
---------- command ------------
> g++ main.cc MyClass.cc
/home/kanze/tmp/ccSi0VUa.o(.text+0x117): In function `MyClass::MyClass()':
: undefined reference to `std::basic_iostream<char,
std::char_traits<char> >::basic_iostream()'
/home/kanze/tmp/ccSi0VUa.o(.text+0x18e): In function `MyClass::MyClass()':
: undefined reference to `std::basic_iostream<char,
std::char_traits<char> >::basic_iostream()'
/home/kanze/tmp/ccSi0VUa.o(.text+0x22d): In function `MyClass::~MyClass()':
: undefined reference to `std::basic_iostream<char,
std::char_traits<char> >::~basic_iostream()'
/home/kanze/tmp/ccSi0VUa.o(.text+0x2de): In function `MyClass::~MyClass()':
: undefined reference to `std::basic_iostream<char,
std::char_traits<char> >::~basic_iostream()'
/home/kanze/tmp/ccSi0VUa.o(.text+0x390): In function `MyClass::~MyClass()':
: undefined reference to `std::basic_iostream<char,
std::char_traits<char> >::~basic_iostream()'
/home/kanze/tmp/ccSi0VUa.o(.gnu.linkonce.r._ZTC7MyClass0_Sd+0xc):
undefined reference to `std::basic_iostream<char, std::char_traits<char>
>::~basic_iostream()'
/home/kanze/tmp/ccSi0VUa.o(.gnu.linkonce.r._ZTC7MyClass0_Sd+0x10):
undefined reference to `std::basic_iostream<char, std::char_traits<char>
>::~basic_iostream()'
collect2: ld returned 1 exit status
----------------------------------
(I know that the above program isn't legal, since it calls the
destructor of ios without ever having invoked ios::init(). But
it should compile and link without problems. I just simplified
to a maximum.)
--
James Kanze mailto: james.kanze@free.fr
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 pl. Pierre Sémard, 78210 St.-Cyr-l'École, France +33 (0)1 30 23 00 34
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Link errors when deriving from iostream (Linux only),
James Kanze <=