No Subject

Patrick Barron barron@adulis.fr
Thu Nov 19 04:28:00 GMT 1998


           Hello,
I have a big problem and I don't have any idears to resolve it.
I have a programm written in C++, and using STL,  and I compile it with
egcs 1.1 b. It built all file.o , but when it try to link. To show you
my problem this is an simple example which generate the same problem :

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 :
g++ -c -I../stl -fguiding-decls principal.cpp
g++ -c -I../stl -fguiding-decls file1-a.cpp
g++ -c -I../stl -fguiding-decls file2-a.cpp
g++ -d -Wall -o essai principal.o file1-a.o file2-a.o
file2-a.o(.bss+0x4): multiple definition of `i1'
file1-a.o(.bss+0x4): first defined here
file2-a.o: In function `global constructors keyed to i1':
file2-a.o(.text+0x0): multiple definition of `global constructors keyed
to i1'
file1-a.o(.text+0x0): first defined here
collect2: ld returned 1 exit status
make: *** [essai] Error 1

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 ?

Sorry for my bad english, but I hope you have understood my problem and
that you have time to answer me .

                   Thank You.
                                    PATRICK BARRON



More information about the Gcc-bugs mailing list