开发者

unresolved external symbol _WinMainCRTStartup

开发者 https://www.devze.com 2023-01-25 23:11 出处:网络
I\'m trying to assemble a simple \"Hello world\" application with Masm32. It assembles fine but when I try to link it, the linker says

I'm trying to assemble a simple "Hello world" application with Masm32. It assembles fine but when I try to link it, the linker says

LINK : error LNK2001: unresolved external symbol _WinMainCRTStartup prog1.exe : fatal error LNK1120: 1 unresolved externals

This is the source code of the program:

.586P

.MODEL FLAT, STDCALL
STD_OUTPUT_HANDLE equ -11

; Prototypes of external procedures
EXTERN GetStdHandle@4:NEAR
EXTERN WriteConsoleA@20:NEAR
EXTERN ExitProcess@4:NEAR

; INCLUDELIB directives for the linker开发者_Go百科
includelib c:\masm32\lib\user32.lib
includelib c:\masm32\lib\kernel32.lib

;============ data segment =================
_DATA SEGMENT
HANDL DWORD ?
BUFER DB "Hello world\n", 0
NUMB  DWORD ?
NUMW  DWORD ?
_DATA ENDS

_TEXT SEGMENT
MAIN:
;====== Get the output handle ======
     PUSH STD_OUTPUT_HANDLE
     CALL GetStdHandle@4
     MOV  HANDL, EAX


; Output the buffer contents to the console
     PUSH 0
     PUSH OFFSET NUMW
     PUSH NUMB
     PUSH OFFSET BUFER
     PUSH HANDL
     CALL WriteConsoleA@20

;Exit application
     PUSH 0
     CALL ExitProcess@4
_TEXT ENDS
END

I found in some forums that this is caused by the encode type. However it doesn't seem to matter to my problem


The linker assumes the default name for entry point. You have a few options.
1. Use the C libraries on the platform, which because you're using MASM, I assume you don't want to.
2. Rename your MAIN to _WinMainCRTStartup
3. Use "-entry:MAIN" on the Link.exe command-line (you may need a "public MAIN" line)


You have 2 Options:

  1. Rename your MAIN to _WinMainCRTStartup
  2. Set Windows (/SUBSYSTEM:WINDOWS) in Properties/Configuration/Linker -> SubSystem option.


You are missing the label after the end statement. It should be the same label that the code segment was labeled with, in your case Main. So instead of your last line being:

END

change it to

END MAIN


Go to project properties << Linker << advanced << Entry Point. Type and Add "MAIN"

then click on apply and press ok.

I Use visual studio 2019.

0

精彩评论

暂无评论...
验证码 换一张
取 消