Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Local static variables

Thread Tools

Local static variables

Richard Hayden
Posts: n/a

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 {
MyClass() {}
~MyClass() {}

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

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.
Reply With Quote
Nicolas Pavlidis
Posts: n/a
Richard Hayden wrote:
> 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
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can local function access local variables in main program? Sullivan WxPyQtKinter Python 10 11-08-2007 02:51 PM
Static inline functions with static local variables Martin Wells C Programming 10 10-08-2007 03:38 PM
Static local variables not allowed in Java ? Razvan Java 7 07-16-2004 08:27 AM
lack of C's static local variables John Davison Java 21 03-06-2004 01:03 AM
a static local variable in a static method is thread local storage? Patrick Hoffmann C++ 3 08-08-2003 02:37 PM