Extern from GCC

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
Tolga

Extern from GCC

Post by Tolga »

Hi people. I wrote isr codes in assembly file like that;

isr0:
pusha
push fs
push gs
push ds
push es

extern _isr0_code
call _isr0_code

pop es
pop ds
pop gs
pop fs
iret

and i write isr0_code to c file;

void isr0_code()
{}

But there is a problem. When am i linking files, linker showing "undefined reference to _isr0_code". But extern command running with kernel "main" function like that;

extern _main
call _main

What is the matter? ???
pini

Re:Extern from GCC

Post by pini »

You can check the object file in which isr0_code is compiled in to see if the symbol is available and under which name with 'objdump'.

Maybe you did declare this symbol as static ?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Extern from GCC

Post by Solar »

Another possibility is that your GCC doesn't prefix C function names with underscores. (This is configuration-dependent.) Again, objdump helps.
Every good solution is obvious once you've found it.
Tolga

Re:Extern from GCC

Post by Tolga »

I used objdump as;

objdump -t kernel.o

-T = Display the contents of the symbol table(s)

it is showing;

... _main
... _Z11isr0_codev

How can i do _Z11isr0_codev same _isr0_code?
dc0d32

Re:Extern from GCC

Post by dc0d32 »

Code: Select all

//no mangling for this function
extern "C" void isr0_code();

void isr0_code()
{
...
}

that should work !
Tolga

Re:Extern from GCC

Post by Tolga »

Hey ok, this is working. Thanks.
guest

Re:Extern from GCC

Post by guest »

C++ encodes the return type and parameter types into the function names, to link against them from assembly you will need to declare the function as extern "C", use C source files or find the mangled name and explicitly link against the mangled version.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Extern from GCC

Post by Solar »

Be aware that there are differences between C and C++. You are compiling your code as C++, which might not be what you intended to do. (For example, C++ does not know about type "long long"...)
Every good solution is obvious once you've found it.
Post Reply