Menu

#1033 static member constructors aren't called

OTHER
closed
gcc (462)
rejected
User_Error
2013-01-25
2007-04-26
Motl
No

Hi,

gcc 3.4.4
ld 2.17.50

When linking against c++ library, static member constructors aren't called before main(), neither for static nor for dynamic linking.

The strange thing here is that it works fine when the library is built on Cygwin with the same compiler/linker.
I 'm not an expert, but it seems to be mingw runtime issue.

Discussion

  • Motl

    Motl - 2007-04-26
    • priority: 5 --> 9
     
  • Danny Smith

    Danny Smith - 2007-04-26
    • priority: 9 --> 5
    • status: open --> pending
     
  • Danny Smith

    Danny Smith - 2007-04-26

    Logged In: YES
    user_id=11494
    Originator: NO

    Testcase please.
    Danny

     
  • Motl

    Motl - 2007-04-27
     
  • Motl

    Motl - 2007-04-27

    Logged In: YES
    user_id=1779125
    Originator: YES

    File Added: static.tgz

     
  • Motl

    Motl - 2007-04-27
    • status: pending --> open
     
  • Danny Smith

    Danny Smith - 2007-04-28

    Logged In: YES
    user_id=11494
    Originator: NO

    The reason that the ctor is not invoked by the app is that the object containing the ctor is not linked in. Look at output of 'nm main.o'.

    To force it to be linked in you could add a non-inline ctor to class Outer, eg
    class Outer
    {
    public:
    Outer();
    private:
    static Inner inn;
    };

    and define
    Outer::Outer(){};
    in the library module s.cpp

     
  • Danny Smith

    Danny Smith - 2007-05-21
    • status: open --> closed-rejected
     
  • Earnie Boyd

    Earnie Boyd - 2013-01-25
    • status: closed-rejected --> closed
    • resolution: --> rejected
    • category: --> User_Error
    • milestone: --> OTHER