Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Link errors when deriving from iostream (Linux only)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
James Kanze  
View profile  
 More options Apr 2 2005, 7:28 am
Newsgroups: gnu.g++.help
From: James Kanze <kanze@none>
Date: Sat, 02 Apr 2005 14:28:45 +0200
Local: Sat, Apr 2 2005 7:28 am
Subject: Link errors when deriving from iostream (Linux only)
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.ka...@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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »