While trying to setup Visual Studio 2019 to compile a .asm project, I am getting an error.
I created an empty c++ project and added a Main.asm
file. I tried both MASM and NASM and get the same error:
LNK1104 cannot open file 'C:\Users\Serge Fonville\source\repos\NASM\x64\Debug\Main.obj'
Both NASM and MASM produce the same error. The mentioned .obj
file is also not present on the location. When compiling manually, it works without issue.
I followed all the guides I could find to set this up, but to no avail.
I removed and reinstalled everything between attemps.
Initially I thought it had to do with MASM (which I tried first), but since NASM gives the same errors, it seems to me it is something else. Unfortunately, I have no idea what.
Before compiling I verified the build extensions for the applicable assembler were enabled and the .asm file had the corresponding item type.
Any help is greatly appreciated.
For reference, the .asm (NASM) I tried to compile: From https://cs.lmu.edu/~ray/notes/nasmtutorial/
; ----------------------------------------------------------------------------------------
; This is a Win64 console program that writes "Hello" on one line and then exits. It
; uses puts from the C library. To assemble and run:
;
; nasm -fwin64 hello.asm && gcc hello.obj && a
; ----------------------------------------------------------------------------------------
global main
extern puts
section .text
main:
sub rsp, 28h ; Reserve the shadow space
mov rcx, message ; First argument is address of message
call puts ; puts(message)
add rsp, 28h ; Remove shadow space
ret
message:
db 'Hello', 0 ; C strings need a zero byte at the end
The MASM file:
;Descr : My First 64-bit MASM program
;ml64 prog.asm /c
;golink /console /entry main prog.obj msvcrt.dll, or
;gcc -m64 prog.obj -o prog.exe (main/ret). This needs 64-bit GCC.
;-----------------------------------
extrn printf:proc
extrn exit:proc
.data
hello db 'Hello 64-bit world!',0ah,0
.code
main proc
mov rcx,offset hello
sub rsp,20h
call printf
add rsp,20h
mov rcx,0
call exit
main endp
end
The output when I do a rebuild:
Rebuild started...
1>------ Rebuild All started: Project: NASM, Configuration: Debug x64 ------
1>LINK : fatal error LNK1104: cannot open file 'x64\Debug\Main.obj'
1>Done building project "NASM.vcxproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
When I dir
for the files
C:\Users\Serge Fonville>dir /s /b c:\main.obj
c:\VTRoot\HarddiskVolume3\Users\Serge Fonville\source\repos\NASM\NASM\x64\Debug\Main.obj