无法解析的外部符号_WinMainCRTStartup
我正在尝试使用 Masm32 组装一个简单的“Hello world”应用程序。它组装得很好,但是当我尝试链接它时,链接器说
LINK:错误 LNK2001:无法解析的外部符号 _WinMainCRTStartup prog1.exe:致命错误 LNK1120:1 个无法解析的外部
这是程序的源代码:
.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
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'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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
链接器采用入口点的默认名称。
您有几个选择。
1. 在平台上使用 C 库,因为您正在使用 MASM,我假设您不想这样做。
2. 将 MAIN 重命名为 _WinMainCRTStartup
3. 在 Link.exe 命令行上使用“-entry:MAIN”(您可能需要“public MAIN”行)
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)
您有 2 个选项:
You have 2 Options:
您缺少结束语句后的标签。它应该与代码段标记的标签相同,在您的情况下为 Main。因此,不要将最后一行:
END
更改为
END MAIN
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
转到项目属性<<链接器<<高级<<入口点。
键入并添加“MAIN”
,然后单击应用并按确定。
我使用 Visual Studio 2019。
Go to project properties << Linker << advanced << Entry Point.
Type and Add "MAIN"
then click on apply and press ok.
I Use visual studio 2019.