'Linking 64-bit NASM with MinGW-64 causes "File format not recognized" error

I am trying to assemble and link a 64-bit NASM program on Windows using MinGW-64bit with the following batch command:

nasm -f win64 HelloWorld.asm && "C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin\gcc.exe" HelloWorld.obj -o HelloWorld.exe

But I get this error:

HelloWorld.obj: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status

How can I fix this?



Solution 1:[1]

It turns out that, although I downloaded and installed MinGW-64, I still got a 32-bit version because I selected the i686 option upon installation. I reinstalled with the "x86-64" option and it fixed the problem.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Daniel Williams