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

Tonny Tzeng tzengym at ms8.hinet.net
Thu Nov 15 21:04:11 EST 2001


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/
This message resent by the uclinux-dev at uclinux.org list server http://www.uClinux.org/



More information about the uClinux-dev mailing list