本文介绍了64 位 NASM 代码与 MinGW 32 的链接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
限时送ChatGPT账号..我写了这段代码:
global _main
extern _printf
section .text
_main:
push message
call _printf
add esp, 4
ret
message:
db 'Hello, World', 10, 0
并尝试从 cmd 运行它.看起来像这样:
and tried to run it from cmd. It looks like that:
C:\Users\user\AppData\Local\bin\NASM>nasm helloworld.asm -f win64 -o helloworld.obj
C:\Users\user\AppData\Local\bin\NASM>gcc helloworld.obj -m64 -o helloworld.exe
helloworld.obj: file not recognized: File format not recognized
collect2: ld returned 1 exit status
我在谷歌中搜索了这个错误,但没有任何与我相关的内容.如您所见,我正在使用 Windows (10).有人知道如何解决这个问题吗?谢谢.
I searched this error in google but nothing was relevant for me. I'm using Windows (10) as you can see. Does someone know how to solve this problem? Thanks.
当我运行 gcc -v 我得到这个:
When I run gcc -v I get this:
Reading specs from C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/specs
Configured with: ../gcc-3.4.5-20060117-3/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry --disable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter --enable-hash-synchronization --enable-libstdcxx-debug
Thread model: win32
gcc version 3.4.5 (mingw-vista special r3)
推荐答案
从您的 gcc -v
输出看来您正在使用 mingw-32.
From your gcc -v
output it looks like you are using mingw-32.
您需要获得 mingw-w64.
此外,Windows 64 位代码中的函数看起来完全不同.按如下方式重写您的代码:
Also, functions in 64-bit code for Windows look completely different. Rewrite your code as follows:
; ----------------------------------------------------------------------------------------
; 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 and align stack
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
本页底部的讨论
这篇关于64 位 NASM 代码与 MinGW 32 的链接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论