如何将X64组件与C++在窗户上?

发布于 2025-02-04 10:50:50 字数 878 浏览 4 评论 0原文

cpp.cpp:

#include <iostream>

extern "C" int returnnum();

int main() { std::cout << returnnum() << "\n"; }

asm.asm:

segment .text
global _returnnum
_returnnum:
    mov rax, 420
    ret

首先,我用nasm -f win64 asm.asm编译了汇编文件。

然后,我用g ++ cpp.cpp asm.obj编译C ++文件。

但这给了我一个错误:

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

我知道我可以将rax更改为eax,并使用-f win32进行编译,但它将有效,但是我想要一个64位的应用程序。有什么办法可以做到这一点?

如果这很有帮助:

g ++ -version:g ++(mingw.org gcc-6.3.0-1)6.3.0
NASM - Version:NASM版本2.15RC12在2020年6月26日汇编

cpp.cpp:

#include <iostream>

extern "C" int returnnum();

int main() { std::cout << returnnum() << "\n"; }

asm.asm:

segment .text
global _returnnum
_returnnum:
    mov rax, 420
    ret

First, I compile the assembly file with nasm -f win64 asm.asm.

Then, I compile the C++ file with g++ cpp.cpp asm.obj.

But this gives me an error:

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

I know that I can change rax to eax and compile with -f win32 and it'll work, but I want a 64-bit application. Is there any way I can do this?

If this is helpful:

g++ --version: g++ (MinGW.org GCC-6.3.0-1) 6.3.0
nasm --version: NASM version 2.15rc12 compiled on Jun 26 2020

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遮云壑 2025-02-11 10:50:50

根据您的信息和您的g ++ -version输出,看起来您似乎安装了平原 mingw (纯粹是32位,并且只需要构建32位可执行文件,因为Windows支持在64位OS上运行32位可执行文件,而不是 mingw-w64 ,具有本机支持64位窗口的叉子。

如果要构建True 64位可执行文件,则需要切换。

Based on your information from the comments and your g++ --version output, it looks like you installed plain MinGW (which is purely 32 bit, and works just fine if you only need to build 32 bit executables since Windows supports running 32 bit executables on a 64 bit OS) rather than MinGW-W64, the fork with native support for 64 bit Windows.

You'll need to switch if you want to build true 64 bit executables.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文