在 MASM 链接器错误中调用 C++ 函数
Calling C++ Functions in MASM Linker Error
所以我目前正在尝试 运行 来自汇编程序的外部 C++ 函数。我有正确的汇编程序 运行ning,但我一直收到链接器错误:
“错误 LNK2019 未解析的外部符号 _testFunc@0 在函数中引用 __main@0”
我想知道为什么会出现此错误,我认为这是因为我以某种方式错误地将我的 C++ 函数导入到我的 asm 程序中,但我看到其他人以类似的方式这样做。
这是我的汇编代码:
; 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
和我的 C++ 代码:
#include <iostream>
using namespace std;
extern "C" void _main();
extern "C" void testFunc()
{
cout << "Hello world";
}
int main()
{
_main();
return 0;
}
您声明.MODEL FLAT, stdcall
。你应该定义函数
extern "C" __stdcall void testFunc()
所以我目前正在尝试 运行 来自汇编程序的外部 C++ 函数。我有正确的汇编程序 运行ning,但我一直收到链接器错误:
“错误 LNK2019 未解析的外部符号 _testFunc@0 在函数中引用 __main@0”
我想知道为什么会出现此错误,我认为这是因为我以某种方式错误地将我的 C++ 函数导入到我的 asm 程序中,但我看到其他人以类似的方式这样做。
这是我的汇编代码:
; 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
和我的 C++ 代码:
#include <iostream>
using namespace std;
extern "C" void _main();
extern "C" void testFunc()
{
cout << "Hello world";
}
int main()
{
_main();
return 0;
}
您声明.MODEL FLAT, stdcall
。你应该定义函数
extern "C" __stdcall void testFunc()