Local static variables

R

Richard Hayden

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.
 
N

Nicolas Pavlidis

Richard said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top