Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GCC with NASM

495 views
Skip to first unread message

Bart

unread,
Apr 16, 2008, 3:26:52 PM4/16/08
to
I'd like to create a project that combines C and ASM files.

I have gcc 3.4.5 for Windows (Mingw). And NASM.

Assuming this is possible:

(1) What options do I give NASM to create an object file compatible
with gcc?

(2) How do I link this file to C files? (I've never used gcc on more
than one file nor used the linker directly).

An example to combine just one .c file and one .asm file would be
great!

Thanks,

--
Bartc

Bart

unread,
Apr 18, 2008, 6:41:01 AM4/18/08
to
On Apr 16, 8:26 pm, Bart <b...@freeuk.com> wrote:
> I'd like to create a project that combines C and ASM files.

Looked like I would have to sort this myself!

The setup is:

gcc 3.4.5 (mingw special) on Windows (not Cygwin)
nasm 2.02

Input files: abc.c, def.asm

I tried using the linker directly, but it is utterly impossible (found
the library libcrtdll.a, then it can't resolve __main or ___main...)

But gcc can be used to invoke the linker indirectly. The steps needed
are:

gcc -c abc.c
(produces abc.o)

nasm -fwin32 def.asm
(produces def.obj)

gcc abc.o def.obj

Links the files, creating (because I don't know how to specify the
output!) a.exe.

So gcc is quite happy working with the .obj output of nasm. (However
I'm dreading the day when I have a more elaborate linking
requirement..)


--
Bart

Michael Klemm

unread,
Apr 18, 2008, 7:07:12 AM4/18/08
to
Bart wrote:
> gcc abc.o def.obj
>
> Links the files, creating (because I don't know how to specify the
> output!) a.exe.

You could try this:

gcc -o mybinary.exe abc.o def.obj

Cheers,
-michael

--
> Nenne mir ein Wort und ich erkläre Dir, daß es griechischen Ursprungs
> ist
Na dann: Semmelknödel und Wolpertinger
(Anastasios Tsitlakidis und Michael Rauscher in d.c.l.j)

signature.asc
0 new messages