2

I have the following code in NASM:

;sleep.asm
[SECTION .text]

global _start


_start:
    xor eax,eax
    mov ebx, 0x00016630 ;address of Sleep
    mov ax, 5000        ;pause for 5000ms
    push eax
    call ebx        ;Sleep(ms);

Where 0x00016630 is the address of Sleep function (taken from dumpbin from kernel32.dll).

I would like to make executable file to run in Win 10. What I did was:

nasm -f win32 sleep.asm

and have sleep.obj as result.

So now I have to link it. I choose link.exe Unfortunately with the following command

link sleep.obj /entry:_start /subsystem:windows /nodefaultlib
Microsoft (R) Incremental Linker Version 14.00.24215.1
Copyright (C) Microsoft Corporation.  All rights reserved.

LINK : error LNK2001: unresolved external symbol __start
sleep.exe : fatal error LNK1120: 1 unresolved externals

Can anybody help how to fix this issue?

Margaret Bloom
  • 41,768
  • 5
  • 78
  • 124
Sebic123
  • 41
  • 1
  • 2
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Ken White Jan 11 '17 at 18:31
  • What if you use `/entry:start`? – Margaret Bloom Jan 11 '17 at 18:34

1 Answers1

5

The linker will automatically pre-pend an underscore to whatever you pass on the command line with /entry. Try this instead:

link sleep.obj /entry:start /subsystem:windows /nodefaultlib
David Hoelzer
  • 15,862
  • 4
  • 48
  • 67