MSVC11 错误中的 x64 位 asm

x64 bit asm in MSVC11 error

本文关键字:asm x64 错误 MSVC11      更新时间:2023-10-16

所以我的解决方案中有两个文件。

测试.asm

.code
test proc
mov eax, 1
ret
test endp
end

资料来源.cpp

#include <iostream>
#include <conio.h>
extern "C" int test();
int main()
{
std::cout << "eax = " << test() << std::endl;
_getch();
return 0;
}

我在配置管理器中将解决方案平台设置为 x64,并在构建自定义中检查了 masm。我找到了两个相关的帖子,但建议没有帮助。我正在YouTube上关注一个视频,并且完全按照作者的方式做了,但是我遇到了这些错误:

1>Source.obj : error LNK2019: unresolved external symbol _test referenced in function main
1>C:UsersomarDesktopASMx64DebugASM.exe : fatal error LNK1120: 1 unresolved externals

有人可以帮助我找出问题所在吗?我真的很想进入 x64 汇编。谢谢

你的汇编程序的函数名称必须是_test的,而不仅仅是test。您可以在链接器的错误消息中看到这一点:

error LNK2019: unresolved external symbol _test
                                          /
                                          ||
right here ---------------------------------

有关更多详细信息,请参阅 Microsoft 窗口中的 C 名称修饰。

假设你在Visual studio上,你需要将程序集文件的名称添加到其他依赖项中。

  1. 右键单击项目
  2. 转到属性
  3. 点击链接器
  4. 点击输入
  5. 在其他依赖项中,添加测试

假设汇编代码工作正常,并且它与c ++源文件位于同一目录中,它应该可以工作

固定。跟着这个

另外,我不得不使用下划线