本文介绍了如何从masm引用外部C ++函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在学习masm,但是在调用外部函数时遇到问题.
I'm currently learning masm and I am having a problem calling an external function.
我在c ++中有一个称为writei的函数,它接收一个uint64并将其输出.
I have a function in c++ which is called writei, it receives a uint64 and outputs it.
int writei(uint64_t a)
{
cout << a;
return 1;
}
我尝试从.asm文件中提取"并调用它,但是编译器抛出在函数mai中引用的未解析的外部符号writei".
I tried "extrn"ing and calling it from an .asm file but the compiler throws "unresolved external symbol writei referenced in function mai".
这是masm代码(我正在使用Visual Studio 2019)
this is the masm code (I'm using visual studio 2019)
extern writei : proto
.code
mai proc
push rbp
push rsp
mov ecx,3
call writei
pop rsp
pop rbp
ret
mai endp
end
推荐答案
除其他事项外,您还需要"extern C" .
Among other things, you need "extern C" in your C++ method declaration.
例如:
extern "C" {
int writei(uint64_t a);
}
int writei(uint64_t a)
{
cout << a;
return 1;
}
这是一篇很好的文章,详细介绍了这一点:
Here's a good article that explains this in more detail:
这篇关于如何从masm引用外部C ++函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!