仅在64位的asm中编译时出现问题:错误LNK2001

问题描述 投票:0回答:1

在编译我的汇编代码时遇到一个问题,当我编译为 64 位而不是 32 位时,我收到错误:

LINK : error LNK2001: unresolved external symbol main
hello.obj : error LNK2001: unresolved external symbol _MessageBoxA@16
hello.exe : fatal error LNK1120: 2 unresolved externals

这是我用于编译的批处理文件(我知道它不能满足所有需求):

@echo off
set /p instructionset="Enter the instruction set (32/64(broken)): "
if %instructionset%==32 (
    set extendedset=86
) else if %instructionset%==64 (
    set extendedset=64
)
set /p asmfile="Enter the name of the assembly file: "
nasm -fwin%instructionset% .\%asmfile%
set /p library="Enter any libraries needed (separated by spaces): "
set objfile=%asmfile:~0,-4%.obj
echo C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22621.0\um\x%extendedset%\%library%
link /entry:main /subsystem:windows %objfile% "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22621.0\um\x"%extendedset%"\\"%library%

这是两个完整的输出

64 位:

Enter the instruction set (32/64(broken)): 64
Enter the name of the assembly file: main.asm
Enter any libraries needed (separated by spaces): User32.Lib
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22621.0\um\x64\User32.Lib
Microsoft (R) Incremental Linker Version 14.29.30153.0
Copyright (C) Microsoft Corporation.  All rights reserved.

LINK : error LNK2001: unresolved external symbol main
hello.obj : error LNK2001: unresolved external symbol _MessageBoxA@16
hello.exe : fatal error LNK1120: 2 unresolved externals

32位:

Enter the instruction set (32/64(broken)): 32
Enter the name of the assembly file: main.asm
Enter any libraries needed (separated by spaces): User32.Lib
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22621.0\um\x86\User32.Lib
Microsoft (R) Incremental Linker Version 14.29.30153.0
Copyright (C) Microsoft Corporation.  All rights reserved.

(编译后的二进制文件工作得很好)

我是个新人,所以我可能会遗漏一些东西,但感谢所有的帮助!

windows assembly nasm
1个回答
0
投票

Hans Passant指出_MessageBoxA@16仅适用于32位模式,仅_MessageBoxA适用于64位

© www.soinside.com 2019 - 2024. All rights reserved.