Page 1 of 1
Extern from GCC
Posted: Sun Jun 04, 2006 10:10 am
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? ???
Re:Extern from GCC
Posted: Sun Jun 04, 2006 10:19 am
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 ?
Re:Extern from GCC
Posted: Sun Jun 04, 2006 10:47 am
by Solar
Another possibility is that your GCC doesn't prefix C function names with underscores. (This is configuration-dependent.) Again, objdump helps.
Re:Extern from GCC
Posted: Sun Jun 04, 2006 1:18 pm
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?
Re:Extern from GCC
Posted: Sun Jun 04, 2006 1:35 pm
by dc0d32
Code: Select all
//no mangling for this function
extern "C" void isr0_code();
void isr0_code()
{
...
}
that should work !
Re:Extern from GCC
Posted: Sun Jun 04, 2006 1:49 pm
by Tolga
Hey ok, this is working. Thanks.
Re:Extern from GCC
Posted: Sun Jun 04, 2006 10:17 pm
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.
Re:Extern from GCC
Posted: Mon Jun 05, 2006 9:03 am
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"...)