Linker error when calling Assembler function in C++

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
david-h
Posts: 17
Joined: Sun Apr 08, 2007 5:48 am
Location: Frankfurt/Main, Germany
Contact:

Linker error when calling Assembler function in C++

Post 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.
User avatar
bluecode
Member
Member
Posts: 202
Joined: Wed Nov 17, 2004 12:00 am
Location: Germany
Contact:

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

Post 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();
david-h
Posts: 17
Joined: Sun Apr 08, 2007 5:48 am
Location: Frankfurt/Main, Germany
Contact:

Post 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:
Post Reply