[英]Calling C++ Functions in MASM Linker Error
所以我目前正在嘗試從匯編程序運行外部 C++ 函數。 我的匯編程序運行正常,但我不斷收到 linker 錯誤消息:
“在 function __main@0 中引用的錯誤 LNK2019 無法解析的外部符號 _testFunc@0”
我想知道為什么我會收到這個錯誤,我認為這是因為我以某種方式錯誤地將我的 C++ function 導入到我的 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
。 您應該定義 function
extern "C" __stdcall void testFunc()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.