This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Shared library bug
- To: egcs-bugs at egcs dot cygnus dot com
- Subject: Shared library bug
- From: "Bogus User" <bogus_user at hotmail dot com>
- Date: Fri, 01 Oct 1999 06:54:25 PDT
Howdy,
I'm running RedHat Linux 6.0 using the version of egcs that comes with it,
gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release).
The problem seems to be that if a variable is declared inside a shared
library, the constructor doesn't get called. If you compile the following
files (should be 3 of them plus a makefile) and try to run it, it seg faults
inside the Standard Template Library code. I've tried this with a newer and
older version of the STL and both give the same results.
If the code is compiled into a static library, then everything runs fine.
----------------- test.cpp ---------------------------------------
#include "test.h"
int main(int argc, char **argv) {
f[0].doStuff();
}
------------------------------------------------------------------
----------------- test1.cpp ---------------------------------------
#include "test.h"
#include <stdio.h>
struct foo f[2];
void foo::doStuff(){
int_map::iterator i = im.find(3);
printf("done\n");
}
------------------------------------------------------------------
----------------- test.h ---------------------------------------
#include <map>
typedef map<int, int, less <int> > int_map;
struct foo {
int_map im;
void doStuff();
};
extern foo f[];
------------------------------------------------------------------
----------------- Makefile ---------------------------------------
CPP = g++ -g
LIB = libtest.so
TARGET = test
all: clean ${LIB} ${TARGET}
test: test.cpp
${CPP} -o test test.cpp -L. -ltest
libtest.so: test1.o
ld -shared -o libtest.so test1.o
test1.o: test1.cpp
${CPP} -o test1.o -c test1.cpp
clean:
rm -f ${TARGET} *.o *.a *.so
------------------------------------------------------------------
Thanks,
Rich
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com