I wrote a C++ project with some assembly code files in it. The project files include a C++ file with a main function, and a test.asm
file.
I configured the project according to the method of this link (external assembly file in visual studio). When I try to build the project, an error occurs.
Here is the file test.asm:
PUBLIC hello_from_asm
EXTERN puts:PROC
.data
hello1 db "Hello from ASM.",0
.code
hello_from_asm PROC
push rbp
mov rbp, rsp
sub rsp, 32 ; Shadow Space
and spl, -16 ; Align stack at 16
lea rcx, hello1
call puts
leave ; Restore stack (rsp) & frame pointer (rbp)
ret
hello_from_asm ENDP
END
I tried to build the project with both Visual Studio 2022 and x64 Native Tools Command Prompt for VS 2022 and got same error.
C:\Users\xxx\source\repos\ConsoleApplication31\ConsoleApplication31>msbuild
Microsoft (R) Build Engine version 17.1.0+ae57d105c for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 3/11/2022 1:41:55 PM.
Project "C:\Users\xxx\source\repos\ConsoleApplication31\ConsoleApplicatio
n31\ConsoleApplication31.vcxproj" on node 1 (default targets).
InitializeBuildStatus:
Touching "x64\Debug\ConsoleA.a1ef7c5e.tlog\unsuccessfulbuild".
_MASM:
Assembling test.asm...
cmd.exe /C "C:\Users\xxx\AppData\Local\Temp\tmpa142d9f35bfd45cd9bb5f72c
5caa0ee0.cmd"
ml64.exe /c /nologo /Zi /Fo"x64\Debug\test.obj" /W3 /errorReport:prompt /Tat
est.asm
'ml64.exe' is not recognized as an internal or external command,
operable program or batch file.
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v1
70\BuildCustomizations\masm.targets(70,5): error MSB3721: The command "ml64.exe
/c /nologo /Zi /Fo"x64\Debug\test.obj" /W3 /errorReport:prompt /Tatest.asm" e
xited with code 1. [C:\Users\xxx\source\repos\ConsoleApplication31\Consol
eApplication31\ConsoleApplication31.vcxproj]
Done Building Project "C:\Users\xxx\source\repos\ConsoleApplication31\Con
soleApplication31\ConsoleApplication31.vcxproj" (default targets) -- FAILED.
Build FAILED.
"C:\Users\xxx\source\repos\ConsoleApplication31\ConsoleApplication31\Cons
oleApplication31.vcxproj" (default target) (1) ->
(_MASM target) ->
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\
v170\BuildCustomizations\masm.targets(70,5): error MSB3721: The command "ml64.e
xe /c /nologo /Zi /Fo"x64\Debug\test.obj" /W3 /errorReport:prompt /Tatest.asm"
exited with code 1. [C:\Users\xxx\source\repos\ConsoleApplication31\Cons
oleApplication31\ConsoleApplication31.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.48