Page 1 of 1
Nasm and GCC
Posted: Fri Dec 12, 2008 9:47 pm
by regedit
I am just wanting to combine a Nasm obj with C obj to create an .exe
But the only compile options I run across are for kernels not aps..
Does any one here know what options are needed?
Nasm -f obj file.asm
GCC ???
how would I link with into a gcc linked exe
Under XP -
nasm
gcc
Re: Nasm and GCC
Posted: Fri Dec 12, 2008 9:55 pm
by Troy Martin
I really don't know, I'm not good at C with OS development, but I think you might need an extern somewhere.
Sorry I can't help much,
Troy
Re: Nasm and GCC
Posted: Fri Dec 12, 2008 10:02 pm
by stephenj
I've never tried this in Windows before, but
this link appears useful.
Re: Nasm and GCC
Posted: Fri Dec 12, 2008 10:35 pm
by regedit
Thanks : stephenj
It worked!
also no extern was needed.. :Troy Martin
but thanks anyway!
you just need to define the funtion in the c app like below:
nasm:
_function:
ret
gcc:
void function();
int main()
{
funtion();
return 0;
}
Re: Nasm and GCC
Posted: Mon Dec 15, 2008 5:18 am
by Khaoticmind
For what i know it might have worked, but the correct way to deal with it is with an extern.
When you do
Code: Select all
void function();
int main()
{
funtion();
return 0;
}
You are telling the compiler that function() will be defined later in the same translation unit (the way C calls a file, so to say). What, obviously is not the case.
This might have worked with ld (what gcc calls to link everything), but is not guaranteed to work in other compilers.
You should do
Code: Select all
extern void function();
int main()
{
funtion();
return 0;
}
To say that function() is in a
extern translation unit (file). And then everything should be ok
Cheers,
KM
Re: Nasm and GCC
Posted: Mon Dec 15, 2008 7:26 am
by Ztane
Khaoticmind wrote:
This might have worked with ld (what gcc calls to link everything), but is not guaranteed to work in other compilers.
Actually,
extern with function declaration should be no-op, see
http://c-faq.com/decl/extern.html.
Re: Nasm and GCC
Posted: Mon Dec 15, 2008 8:03 am
by Khaoticmind
Ztane wrote:Khaoticmind wrote:
This might have worked with ld (what gcc calls to link everything), but is not guaranteed to work in other compilers.
Actually,
extern with function declaration should be no-op, see
http://c-faq.com/decl/extern.html.
Good point! Otherwise no linking would ever work with my code
My mistake!