使用 c++ 链接 Windows .obj 文件使用 NetBeans/GCC/NASM 的项目

发布于 2024-10-04 14:35:28 字数 327 浏览 0 评论 0原文

发布时间:2010 年 11 月 22 日星期一凌晨 2:30 帖子主题:如何将程序集对象与 C++ 项目链接
你好,

我正在尝试将汇编程序与我的 C++ 程序链接起来。我使用 NASM 通过命令“nasm -fobj myprogram.asm”生成 .obj 文件。 .obj 文件已创建,但我不确定如何将其与我的项目链接。我尝试将文件添加到链接器->依赖项,但仍然收到错误消息,表明我的外部汇编函数未定义。也许 .obj 文件位于错误的目录中(它与 .cpp 文件一起位于根项目文件夹中)?

谁能简单解释一下如何将汇编语言 .obj 文件与我的项目链接?

谢谢, -KB

Posted: Mon Nov 22, 2010 2:30 am Post subject: How to link an assembly object with a c++ project
Hello,

I'm trying to link an assembly program with my c++ program. I'm using NASM to generate the .obj file with the command "nasm -fobj myprogram.asm". The .obj file is created, but I'm not sure how to link this with my project. I tried adding the file to Linker->Dependencies, but I still get the error that my external assembly function is not defined. Maybe the .obj file is in the wrong directory(it's in the root project folder, along with the .cpp files)?

Can anyone give a simple explanation about how to link an assembly language .obj file with my project?

Thanks,
-KB

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

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

发布评论

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

评论(1

百思不得你姐 2024-10-11 14:35:28

确保在汇编代码中适当地修改了名称。
IIRC,__stdcall 在 32 位 MSVC 中默认使用,它在前面添加下划线并附加 @[参数字节]。
因此,size_t strlen( const char *str ),如果编译 __stdcall 将被破坏为
_strlen@4

请查看此处此处了解更多详细信息。

Make sure you mangle the name appropriately in the assembler code.
IIRC, __stdcall is used by default in 32 bit MSVC and it prepends an underscore and appends @[bytes of arguments].
So, size_t strlen( const char *str ), if compiled __stdcall would be mangled to
_strlen@4.

Look here or here for more details.

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