Page 1 of 1

Linker error when calling Assembler function in C++

Posted: Sun Apr 29, 2007 2:57 am
by david-h
Hi,
I´m reading this kernel tutorial. I´m now at the chapter about the GDT, and because I want a C++ kernel I made some changes at the code.

The header file looks like this:

Code: Select all

//function is defined in Loader.asm
extern void gdt_flush();

namespace GDT
{
	//registers a GDT
	void set_gate(int num, unsigned long base, unsigned long limit, unsigned char access, unsigned char gran);
	//installs default GDTs
	void install();
}
The definition of the function is the same like in the tutorial.

In my asm file I defined gdt_flush, exactly the same like the one from the tutorial.

Everything compiles fine, but if I want to link the .o files, I get an error in file GDT.o: undefined reference to '__Z9gdt_flushv'.

I have no idea what is wrong with my code.

Re: Linker error when calling Assembler function in C++

Posted: Sun Apr 29, 2007 3:00 am
by bluecode
Declare the gdt_flush function as extern "C", which will tell C++, that the function name should not be mangled.

Code: Select all

//function is defined in Loader.asm
extern "C" void gdt_flush();

Posted: Sun Apr 29, 2007 3:23 am
by david-h
Tanks you very much. That worked fine.

Hope you cna answer my next question so quick too, I guess I will ask a lot. :wink: