无法解析的外部符号_WinMainCRTStartup

发布于 2024-10-03 18:34:46 字数 1064 浏览 0 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

猫七 2024-10-10 18:34:46

链接器采用入口点的默认名称。
您有几个选择。
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)

小糖芽 2024-10-10 18:34:46

您有 2 个选项:

  1. 将 MAIN 重命名为 _WinMainCRTStartup
  2. 在 Properties/Configuration/Linker -> Set Windows (/SUBSYSTEM:WINDOWS) ->子系统选项。

You have 2 Options:

  1. Rename your MAIN to _WinMainCRTStartup
  2. Set Windows (/SUBSYSTEM:WINDOWS) in Properties/Configuration/Linker -> SubSystem option.
自演自醉 2024-10-10 18:34:46

您缺少结束语句后的标签。它应该与代码段标记的标签相同,在您的情况下为 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

卖梦商人 2024-10-10 18:34:46

转到项目属性<<链接器<<高级<<入口点。
键入并添加“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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文