[uClinux-dev] The constructor of global variable cann't be executed in C++

kjlin kj.lin at viditec-netmedia.com.tw
Sun Nov 18 20:34:27 EST 2001


Hi Tonny,

I really appreciate your instruction.
My x-compiler is mips-linux-gcc.
And as you say, after i added the handler in the crt0.c to deal with the
.ctors
and .dtors list the problem was resolved.
Thanks very much.

KJ
----- Original Message -----
From: "Tonny Tzeng" <tzengym at ms8.hinet.net>
To: <uclinux-dev at uclinux.org>
Sent: Friday, November 16, 2001 10:04 AM
Subject: Re: [uClinux-dev] The constructor of global variable cann't be
executed in C++


> Dear KJ,
>
> What's the build target of your cross compiler? Are you using
> mips-linux-gcc or mips-elf-gcc?
> For elf-gcc, the compiler will generate a subroutine call to __gccmain
> after the prologue of main(), and __gccmain will execute each global
> constructor in the global constructor list in '.ctors' section. The
handler
> of global destructors will submit to atexit() in __gccmain also.
> If you are using linux-gcc compiler, I think you have to deal with .ctors
> and .dtors lists explicitly in your runtime startup file (ex. crt0.S in
> uClibc).
>
> Best regards,
> Tonny
>
> >I am using uclinux-2.4.1+MIPS and compiler is gcc-2.96 20000731.
> >All the APs which written by C code are executed very well in my
> uclinux+MIPS.
> >Howerer, the APs made by C++ are not so fine.
> >The C++ problem is that the constructor of a global object will not be
> executed,
> >but the constructor of a local object is executed normally.
> >For example:
> >
> >#include <stdio.h>
> >class A{
> >public:
> >           A(int id) { printf("The constructor ID=%d!\n", id); };
> >};
> >
> >A out(0);                        // global
> >
> >int main()
> >{
> >    A in(1);                      // local
> >    return 0;
> >}
> >The output is:
> ># The constructor ID=1
> >
> >Only the constructor of the local variable "in" was executed.
> >Is it the problem of compiler or my uClibc or linker script??
> [snip]
>
>
> This message resent by the uclinux-dev at uclinux.org list server
http://www.uClinux.org/

This message resent by the uclinux-dev at uclinux.org list server http://www.uClinux.org/



More information about the uClinux-dev mailing list