From: dstewart+@cs.cmu.edu (David B Stewart)
Newsgroups: gnu.g++.help
Subject: Need help installing iostreams library
Date: 26 Sep 92 18:35:01 GMT
Article-I.D.: cs.Bv77MF.K8n.1
Organization: The Robotics Institute, Carnegie Mellon University
Cc: dstewart


I am trying to get g++ to work with the Chimera 3.0 Real-Time Operating System
developed here at CMU.  Everything seems to be working fine except for the
"iostreams" library. (I tested a few things by using stdio library to print
output).

When I try to compile the following simple Hello World program using streams, I
get the following problems with symbols:

iostream.o: multiple definition of `___rs__FR7istreamRUc (.text)' 
hello.o: first seen here
stdstreams.o: multiple definition of `___rs__FR7istreamRUc (.text)' 
hello.o: first seen here
igetline.o: multiple definition of `___rs__FR7istreamRUc (.text)' 
hello.o: first seen here
makebuf.o: multiple definition of `___rs__FR7istreamRUc (.text)' 
hello.o: first seen here
undefined reference to `___vtbl__7filebuf'
undefined reference to `___vtbl__7filebuf'
undefined reference to `___vtbl__7filebuf'
undefined reference to `___vtbl__7filebuf'

The multiply-defined symbol is indeed in all the .o files, but I can't
figure out what the non-mangled name is, so that I can figure out
how to fix that problem.

The file stdstrbufs.C has a statement "extern char vt_filebuf[1]", which is the
source of the undefined symbol.  The comment in the file says "vt_filebuf" must
evaluate to the address of the virtual function table for the filebuf class,
then proceeds to define vt_filebuf as __vtbl__7filebuf.  I am not sure what
this means, nor how to fix it.

As a fix that I am not surprised doesn't work, I defined "char vt_filebuf[1]"
so that my program would at least generate an executable without the undefined
symbol.  When I run it, the program crashes at the cout << "Hello World" line
with an "Address Error", which I suspect is a result of cout not being properly
initialized.

Second, which constructor routines should be called when I have the
simple program:

    #include <iostream.h>
    main() { cout << "Hello World"}

I put printf's in all the constructor routines in the IOstream library, and the
only one that shows up is from the "struct __io_defs" in streambuf.C, which is
an empty subroutine.  It seems to me that initializing something like cout
would require at least some form of initialization.  I looked at the
disassembled code, and the __CTOR_LIST__ contains one entry, which is
__GLOBAL_$I_least_marker__9streambuf.  My guess is that would be
the routine streambuf::_least_marker(), since that is the only thing close
to the symbol that exists in the iostream source code.  However, I
put a printf() statement in streambuf::_least_marker(), but that line
never prints out.  When I look at the disassembled code, the code
at __GLOBAL_$I_least_marker__9streambuf() does not include my printf(),
and it does call the __io_defs() constructor, leading me to believe
that by guess as to what the mangled name stood for is wrong.  
Are you able to help me decipher what is not working with this stuff?

One other question:  how does the iostreams interact with the operating
system?  I would assume it makes use of the open/read/write system calls, etc.
However, in scanning through the iostream source code, I can't find any such
calls.  So how dependent is the g++ streams library on the operating system?
Chimera 3.0 uses a modified version of the stdio library in order to handle the
concurrency problems that may occur in a lightweight process model, and all the
system calls are emulated as subroutine calls with transparent remote procedure
calls.

Thanks a whole bunch!

~dave

-------------------------------------------------------------------------------
David B. Stewart  - email: <dstewart@cmu.edu>            The Robotics Institute
snail mail:       - ECE Dept., Carnegie Mellon University, Pittsburgh, PA 15213
Current Projects: - Chimera 3.0 Real-Time Operating System
		  - Reconfigurable Sensor-Based Control Systems
Newsgroups: gnu.g++.help,comp.lang.c++