This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re:
- To: "Patrick Barron" <barron at adulis dot fr>, <egcs-bugs at cygnus dot com>
- Subject: Re:
- From: "Ross Smith" <ross dot s at ihug dot co dot nz>
- Date: Fri, 20 Nov 1998 09:27:27 +1300
From: Patrick Barron <barron@adulis.fr>
>
>in file f.h :
>template <class T>
>T& foo( T* )
>{
>static T my_data;
>return my_data;
>};
>
>in file file1-a.cpp :
>#include "f.h"
>int& i1 = foo( (int*) 0);
>
>in file file2-a.cpp :
>#include "f.h"
>int& i1 = foo( (int*) 0);
>
>int the file main
>#include "f.h"
>int main()
>{
>return 1;
>}
>
>So, when the compiler try to link then I have this error :
>file2-a.o(.bss+0x4): multiple definition of `i1'
>
>I read that the problem comes frome the static variable. But in the
>programm where I try to insert the STL is very big and need some static
>varible. So, how can I resolve this problem ?
There is a problem with your code; it's not an EGCS bug, and has
nothing to do with the STL.
You've broken the "one definition rule" by defining i1 twice. If you
intended each of the two modules to have its own separate version of
i1, you should either declare them "static" or put them in an
anonymous namespace. If you intended them both to share a single
global i1, you should declare it "extern" in a header file and define
it in only one of the source modules.
--
Ross Smith ................................... mailto:ross.s@ihug.co.nz
.............. The Internet Group, Auckland, New Zealand ..............
* * * * *
"We're bored. We're armed. And we're off the medication."