Author Topic: Compile file.asm under Windows  (Read 17147 times)

Offline Neutral

  • Jr. Member
  • *
  • Posts: 4
Compile file.asm under Windows
« on: July 11, 2017, 09:20:34 PM »
Code: [Select]
ld hello_world2.o -o hello_world2.exe
Quote
'ld' is not recognized as an internal or external command,
operable program or batch file.

How it fix?
« Last Edit: July 11, 2017, 09:22:09 PM by Neutral »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Compile file.asm under Windows
« Reply #1 on: July 11, 2017, 09:42:38 PM »
Didn't we just have this question? Yeah, here:

https://forum.nasm.us/index.php?topic=2348.0

except it's ld not Nasm that's not on your path. Should be the same solution. This assumes that you've got ld installed. Have you?

Best,
Frank


Offline Neutral

  • Jr. Member
  • *
  • Posts: 4
Re: Compile file.asm under Windows
« Reply #2 on: July 12, 2017, 11:23:06 AM »
I write:

Code: [Select]
gcc -o garage.exe garage.obj
Quote
undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Compile file.asm under Windows
« Reply #3 on: July 12, 2017, 03:18:54 PM »
Well, have ya got a "WinMain@16"?

You confirm something I thought I remembered: the default output name from "-f win32" is ".obj" not ".o". Looks like you're closing in on it. Courage!

Best,
Frank


Offline Neutral

  • Jr. Member
  • *
  • Posts: 4
Re: Compile file.asm under Windows
« Reply #4 on: July 12, 2017, 08:42:29 PM »
How it fix?

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Compile file.asm under Windows
« Reply #5 on: July 12, 2017, 09:18:38 PM »
What have you got? Apparently, Windows example files are hard to find. I would guess...
Code: [Select]
global WinMain@16
extern ExitProcess@4

; entrypoint
WinMain@16

    push 0
    call ExitProcess@4
    ; ret 16 ; might work instead

Some or all of those may need a leading underscore. You can add that on the command line without changing the source code with "--prefix _'. That's a wild assmed guess. I haven't run Windows since win98. You Windows guys have got to stick together. I can't do it for ya.

Best,
Frank


Offline Neutral

  • Jr. Member
  • *
  • Posts: 4
Re: Compile file.asm under Windows
« Reply #6 on: July 13, 2017, 02:12:18 PM »
Code: [Select]
[bits 32]
 
 extern _puts
 
 
 section .data
 
 hello:
db "helllosdjflsdf ",0xa,0

section .text

push hello
call _puts
add esp, 4

xor eax, eax
ret

Code: [Select]
nasm -f win32 -p rial.obj rial.asm
dir rial.obj
ld rial.obj -o rial.exe
ld rial.obj -o rial.exe c:\windows\system32\msvcrt.dll
rial.exe

or

Code: [Select]
nasm -fwin32 helloworld.asm
gcc helloworld.obj
a

or

Code: [Select]
nasm -f elf message_box.asm
gcc -o message_box.exe -mwindows messag_box.o
message_box

or

Code: [Select]
nasm -f win32 my_name_file
gcc -nostdlib -o my_name_file.exe my_name_file.obj -luser32

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Compile file.asm under Windows
« Reply #7 on: July 14, 2017, 03:57:54 AM »
Thanks, Neutral. That should give us something to work with. Unfortunately I can't try 'em for you. I'm not going to install Windows, sorry.

I can tell you for sure "-f elf" isn't going to work for Windows. "-f win32" should be correct. Do all of these complain about "WinMain@16"? I would "expect" that gcc would be looking for "_main", but I haven't run Windows for a long time! "_WinMain@16" is probably the "true entrypoint" but I would expect it to be in the C startup code - the code that calls "_main". I probably steered you wrong showing it without the underscore. Sorry.

Try something like this (based on your code):

Code: [Select]
; nasm -f win32 myprog.asm
; gcc -o myprog.exe myprog.obj

 [bits 32]
 
 extern _puts
global _main
 
 section .data
 
 hello:
db "helllosdjflsdf ",0xa,0

section .text
_main:

push hello
call _puts
add esp, 4

xor eax, eax
ret

"myprog" should be replaced by whatever you called it, of course. If that doesn't work, try replacing "_main" with "_WinMain@16" if that's what it seems to want, or tell us what the error message says.

Where are our other Windows users? I know we've got some! Maybe they're on vacation... Hang in there, Neutral!

Best,
Frank