NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: Neutral on July 11, 2017, 09:20:34 PM
-
ld hello_world2.o -o hello_world2.exe
'ld' is not recognized as an internal or external command,
operable program or batch file.
How it fix?
-
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
-
I write:
gcc -o garage.exe garage.obj
undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
-
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
-
How it fix?
-
What have you got? Apparently, Windows example files are hard to find. I would guess...
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
-
[bits 32]
extern _puts
section .data
hello:
db "helllosdjflsdf ",0xa,0
section .text
push hello
call _puts
add esp, 4
xor eax, eax
ret
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
nasm -fwin32 helloworld.asm
gcc helloworld.obj
a
or
nasm -f elf message_box.asm
gcc -o message_box.exe -mwindows messag_box.o
message_box
or
nasm -f win32 my_name_file
gcc -nostdlib -o my_name_file.exe my_name_file.obj -luser32
-
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):
; 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