So I am currently trying to run external C++ functions from an assembly program. I have assembly programs running properly, but I keep getting a linker error saying:
"Error LNK2019 unresolved external symbol _testFunc@0 referenced in function __main@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.
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:
#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
. You should define the function
extern "C" __stdcall void testFunc()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.