Nasm and GCC

Programming, for all ages and all languages.
Post Reply
regedit
Posts: 7
Joined: Wed Nov 12, 2008 7:23 pm

Nasm and GCC

Post 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

Code: Select all

[BITS 32]
_Some_function:

ret

gcc

Code: Select all

int main()
{
    Some_function();
}
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Nasm and GCC

Post 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
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
stephenj
Member
Member
Posts: 140
Joined: Wed Jul 23, 2008 1:37 am
Location: Canada

Re: Nasm and GCC

Post by stephenj »

I've never tried this in Windows before, but this link appears useful.
regedit
Posts: 7
Joined: Wed Nov 12, 2008 7:23 pm

Re: Nasm and GCC

Post by regedit »

Thanks : stephenj
It worked!
:D
also no extern was needed.. :Troy Martin
but thanks anyway! :wink:

you just need to define the funtion in the c app like below:
nasm:
_function:

ret

gcc:
void function();
int main()
{
funtion();
return 0;
}
User avatar
Khaoticmind
Member
Member
Posts: 29
Joined: Tue Nov 18, 2008 1:06 pm
Location: Brazil

Re: Nasm and GCC

Post 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
Ztane
Posts: 9
Joined: Sun Jan 14, 2007 12:43 pm
Location: Oulu, Finland

Re: Nasm and GCC

Post 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.
User avatar
Khaoticmind
Member
Member
Posts: 29
Joined: Tue Nov 18, 2008 1:06 pm
Location: Brazil

Re: Nasm and GCC

Post 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!
Post Reply