Local static variables

Discussion in 'C++' started by Richard Hayden, Sep 14, 2004.

  1. Hi,

    I'm trying to port my O/S kernel from C to C++. I am using g++ with the
    following command-line switches:

    -Wall -fno-builtin -fno-rtti -fno-exceptions -fno-enforce-eh-specs
    -nostartfiles -nostdinc -nostdlib

    And ld to link it with the -nostdlib switch. There is no C library
    available to link with and I assumed I had disabled it with the above
    switches. However, if I try and use a local static variable, for example in:

    class MyClass {
    private:
    MyClass() {}
    ~MyClass() {}

    MyClass(const MyClass&);
    MyClass& operator=(MyClass);

    public:
    static MyClass& getInstance() {
    static MyClass instance;
    return instance;
    }
    };

    I get undefined references to __cxa_atexit and __dso_handle. I assume
    these are C library functions? What are they for?

    Why are they necessary simply for dealing with static variables; I
    thought they [static variables] were just stored in the global data area
    like global variables? I obviously have not provided the correct
    switches to g++ for it to fully stop trying to use the C library. I'd be
    very grateful if someone could inform me of the correct/complete ones
    and tell me what's going on here!

    Thanks, any help is gratefully received!

    Richard Hayden.
    Richard Hayden, Sep 14, 2004
    #1
    1. Advertising

  2. Richard Hayden wrote:
    > Hi,


    Hi!

    [...]
    >
    > I get undefined references to __cxa_atexit and __dso_handle. I assume
    > these are C library functions? What are they for?


    I can only say, that atexit() is a C - Library function, which is used,
    I think by the sopurce the compiler makes out of your program. There are
    some necessary cleanups, which you don;t see, but they have to be done
    at time of terminating a program.

    HTH && kind regards
    Nicolas
    Nicolas Pavlidis, Sep 14, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Davison

    lack of C's static local variables

    John Davison, Mar 3, 2004, in forum: Java
    Replies:
    21
    Views:
    978
  2. Razvan
    Replies:
    7
    Views:
    32,879
    Tor Iver Wilhelmsen
    Jul 16, 2004
  3. Patrick Hoffmann
    Replies:
    3
    Views:
    2,815
    Christian Jan├čen
    Aug 8, 2003
  4. Martin Wells

    Static inline functions with static local variables

    Martin Wells, Oct 6, 2007, in forum: C Programming
    Replies:
    10
    Views:
    695
    Army1987
    Oct 8, 2007
  5. Sullivan WxPyQtKinter
    Replies:
    10
    Views:
    639
    Antoon Pardon
    Nov 8, 2007
Loading...

Share This Page