[英]Calling C++ Functions in MASM Linker Error
So I am currently trying to run external C++ functions from an assembly program.所以我目前正在尝试从汇编程序运行外部 C++ 函数。 I have assembly programs running properly, but I keep getting a linker error saying:
我的汇编程序运行正常,但我不断收到 linker 错误消息:
"Error LNK2019 unresolved external symbol _testFunc@0 referenced in function __main@0" “在 function __main@0 中引用的错误 LNK2019 无法解析的外部符号 _testFunc@0”
I'm wondering why I am getting this error, I assume it's because I'm somehow incorrectly importing my C++ function into my asm program, but I've seen other people do it in a similar way.我想知道为什么我会收到这个错误,我认为这是因为我以某种方式错误地将我的 C++ function 导入到我的 asm 程序中,但我见过其他人以类似的方式这样做。
Here's my assembly code:这是我的汇编代码:
; Created with MASM
.386
.MODEL FLAT, stdcall
.STACK 100h
ExitProcess PROTO, dwExitCode:DWORD
extern testFunc : proto
.CODE
_main PROC
call testFunc
xor edi, edi
INVOKE ExitProcess, 0
_main ENDP
END
and my C++ code:和我的 C++ 代码:
#include <iostream>
using namespace std;
extern "C" void _main();
extern "C" void testFunc()
{
cout << "Hello world";
}
int main()
{
_main();
return 0;
}
You declare .MODEL FLAT, stdcall
.您声明
.MODEL FLAT, stdcall
。 You should define the function您应该定义 function
extern "C" __stdcall void testFunc()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.