How link obj file from NASM with link.exe in Win10

霸气de小男生 提交于 2019-12-13 15:55:24

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/41598005/how-link-obj-file-from-nasm-with-link-exe-in-win10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!