如何将X64组件与C++在窗户上?
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.0NASM - 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.0nasm --version
: NASM version 2.15rc12 compiled on Jun 26 2020
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的信息和您的
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.