Page 1 of 1
nasm and c
Posted: Tue Feb 26, 2002 3:39 am
by Whatever5k
I want to call a C-function in nasm... .
So I declare my main c-function like this:
extern _kernel_main
and I call it like this:
call _kernel_main
In my main-c-file I have
void kernel_main()
ld sais he cannot find _kernel_main. Why not? I thought I have to declare c-functions in assembler always with a '_' in front.
Re: nasm and c
Posted: Tue Feb 26, 2002 6:56 am
by roswell
you're right, you must declare the function name with an underscore.
I think the error is in the compiled c object.
If you've compiled with the c++ extension of your compiler, the function name is modified in the obj. The reason is that C++ can handle multiple use of a function name if the functions have different arguments.
So in the compiled obj, the symbol is not _function_name, but _function_name@argument_type. The linker can not handle this modification.
To ensure that this is this problem in your case, you can use the objdump utility to see which symbols are exported by an obj file.
To avoid this problem in your c code, you must add :
#ifdef _cplusplus
extern "C" {
#endif
//
Re: nasm and c
Posted: Tue Feb 26, 2002 6:58 am
by roswell
i finish sorry I have validated by error
// Declare the prototype of your functions
#ifdef _cplusplus
}
#endif
I think this you solve your problem. If not, I don't know why.
Roswell
Re: nasm and c
Posted: Wed Feb 27, 2002 3:20 am
by Whatever5k
No, it's because I compiled my asm file in ELF. ELF doesn't need '_'