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.
nasm and c
Re: nasm and c
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
//
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
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
// Declare the prototype of your functions
#ifdef _cplusplus
}
#endif
I think this you solve your problem. If not, I don't know why.
Roswell