Linking: C++ and static variables
Posted: Fri Aug 27, 2004 1:11 pm
I'm trying to use static variables with C++ in my kernel. Here's what the code looks like:
The code compiles fine, but it won't link. I get the following linker error:
Using objdump, I can see all my static method and the section is in "text". I can also see my static variable, but where the section name is, it says "*UND*". Using objdump -r I can see them there.
My linker script looks like this:
Is there something I need to add to my linker script to get this to work or what?
Thanks in advance guys.
Code: Select all
class FooClass
{
private:
static int foo;
public:
static void bar (void);
};
...
void FooClass::bar (void)
{
foo = 0;
}
Code: Select all
fooclass.o(.text+0x20): In function `FooClass::bar()':
: undefined reference to `FooClass::foo'
My linker script looks like this:
Code: Select all
OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
. = 0x00100000;
.text ALIGN (0x1000) :
{
*(.text)
*(.rodata*)
}
.data ALIGN (0x1000) :
{
start_ctors = .;
*(.ctor*)
end_ctors = .;
start_dtors = .;
*(.dtor*)
end_dtors = .;
*(.data)
}
.bss ALIGN (0x1000) :
{
_sbss = .;
*(COMMON)
*(.bss)
_ebss = .;
}
}
Is there something I need to add to my linker script to get this to work or what?
Thanks in advance guys.