Where to start ?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
jason7007

Re:Where to start ?

Post by jason7007 »

Hi,

CjMovie, I did what you posted, but still not working.
ld complains: PE operation of non PE file.


What's wrong here?
Please help.
Phugoid

Re:Where to start ?

Post by Phugoid »

Then try

Code: Select all

nasm -f win32 -o start.o start.asm
It's a Cygwin system after all.
jason7007

Re:Where to start ?

Post by jason7007 »

Hi,

Still, ld not linking, complains PE operation on non PE file.
Phugoid

Re:Where to start ?

Post by Phugoid »

Have you tried -f gnuwin32? Which ones have you tried? Have you read the help output?
jason7007

Re:Where to start ?

Post by jason7007 »

Hi,
I tried these 2 methods:

1)nasmw -f win32 -o start.o start.asm
the above command will result to ld complaining of PE operation on non PE file

2)nasmw -f gnuwin32 -o start.o start.asm
the above command will result to namsw complaining of
unrecognized file output format
Phugoid

Re:Where to start ?

Post by Phugoid »

Your Cygwin should have nasm (no w). Try that.
JAAman

Re:Where to start ?

Post by JAAman »

nasm is just another name for nasmw iirc (they both exist for backward compatability)

try reading the nasm help file -- it talks about two methods of assembling to PE, depending on which tools your using -- don't remember the details

the nasm help file is online: just google nasm help should find it (its my start page on my development system, but im not on it right now)
Phugoid

Re:Where to start ?

Post by Phugoid »

nasmw is just another name for nasm, but usually indicates a different kind of build, targeted for native Win32 and therefore lacking support for the output format jason7007 needs.
jason7007

Re:Where to start ?

Post by jason7007 »

Hi,
I am using nasmw for windows because my os is windows XP,
is nasm for DOS good for windows xp?
Phugoid

Re:Where to start ?

Post by Phugoid »

Your OS is effectively Cygwin, so try to use the nasm that comes with it (hint: look in cygwin/bin). It should support the gnuwin32 format. If you don't have it, use Cygwin's setup.exe program to install it.
jason7007

Re:Where to start ?

Post by jason7007 »

Hi,
I changed from nasmw to nasm. And nasm.exe is already in cygwin/bin. But to no avail.

The same complain of nasm or the ld.
Phugoid

Re:Where to start ?

Post by Phugoid »

Your Cygwin-provided NASM does not support gnuwin32? Are you sure you are not using some other executable named nasm.exe?

Code: Select all

$ nasm -hf
...
gnuwin32  GNU MinGW32/Cygwin Win32 (i386) object files
...
jason7007

Re:Where to start ?

Post by jason7007 »

Hi,
I am 100% sure , I have only one nasm.exe, and that is in Cygwin\bin
Phugoid

Re:Where to start ?

Post by Phugoid »

Ah, I am sorry for not trying this earlier.

I inferred from your posts that you are using the "stock" tools provided with Cygwin, and not a cross-compiler. These tools are targeted for i386-pe and not aout, as the example in Bran's tutorial is. Here is what you need to do to start.asm and the linker script to make them PE-compatible:

In start.asm, insert the line

Code: Select all

[section .text]
immediately after

Code: Select all

[BITS 32]
In the linker script, change

Code: Select all

OUTPUT_FORMAT("binary")
to

Code: Select all

OUTPUT_FORMAT("pe-i386")
And use

Code: Select all

nasm -f win32 -o start.o start.asm
to assemble; use the same command as before to link.

I hope this helps!
jason7007

Re:Where to start ?

Post by jason7007 »

Hi Phugoid,

I followed all steps that you posted, but a different problem came up.
Here are the messages from ld

main.o:main.c:(.text+0x9d):undefined reference to '_alloca'
main.o:main.c:(.text+0xa2):undefined reference to '_main'


Thank you anyway for your time.
Post Reply