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]

Re: multiple definitions of....


Jason Merrill writes:
 > >>>>> Orn E Hansen <oe.hansen@oehansen.pp.se> writes:
 > 
 > >   As was reported yesterday, the new snapshot has a problem with strings.
 > > Now, it isn't difficult to compile bastring.cc as a template class, and
 > > include it, but in a program I get this additional error
 > 
 > We'll need a testcase if we're going to fix this.
 > 

 Well, I tried using bastring.cc, bastring.h and stlinst.cc from 1201
snapshot, and then recompiling.  Doing this got rid of the first
reported error messages, but the *alloc_template<false,0> message were 
now reversed to *alloc_template<true,0>, and these were now missing,
not multiple redefinitions.

  Following this I reversed the 01-07 diffs.  Returning the sources
back to the 1201 snapshot and then did "make" again.  This, I figured,
would rebuild the libraries, which it did... but the errors remained.
I needed to bootstrap the compiler, and after this the reverseing to
1201 snapshot worked fine.  As far as I can understand from the above, 
this looks like a problem with the linker, and not the library itself
(I guess this is the difference between doing a "make" and "make
bootstrap", the latter builds a temporary "xgcc" to build the compiler 
and libraries, while the former only updates what has changed?

 To try and use strings with 1207 snapshot, I made a small string
template class...

---- strings.C

#include <std/bastring.cc>

template class basic_string<char>;

----

 and tested it with...

---- str.C
#include <iostream.h>
#include <string>

main()
{
  string str;

  str = "Halló heimur";
  cout << str.c_str() << endl;
  str += "þarna úti!";
  cout << str.c_str() << endl;
}
----

Compiling...

g++ -c strings.C
g++ str.C strings.o -o str

is OK.

and running, gives correct output.  However, if you split a mainfile
into parts.  I have an application split into several object files,
each uses string.  Basically this would look like (a representation of 
the abstract application used to get the error).

---- str1.h
#include <iostream.h>
#include <string>

class error {
public:
  error();
  ~error();

  void anError();
};

---- str1.C
#include "str1.h"

error::error()
{
}

error::~error()
{
}

void error::anError()
{
  string t;

  t = "String is now in two files";
  cout << t.c_str() << endl;
}

---- str2.C
#include <iostream.h>
#include <string>

#include <str1.h>

main()
{
  error foo;
  string s;

  s = "Halló heimur";
  cout << s.c_str() << endl;
  foo.anError();
}
----

and compiling...

g++ -c strings.C
g++ -c str1.C
g++ -c str2.C
g++ str2.o str1.o strings.o -o str

results in the reporting of multiple definitions of
  __default_alloc_template<false,0>



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