VSNASM
VSNASM copied to clipboard
State Error LNK2001 unresolved external symbol _mainCRTStartup
Whats wrong?
I'm assuming that you're trying to write just assembly and nothing else, but it's in a C++ project. Under the hood in C++ int main
is not the first thing that is called when your program starts, there is setup required for the C runtime to work correctly and the setup function for that (_mainCRTSetup
) is generated by the compiler. If all you want is to run assembly while being able to get CRT functions (like malloc
) I'd suggest just defining something like extern "C" int asmMain()
in a C++ file and call it from C++ like so:
#include <iostream>
extern "C" int asmMain();
// _mainCRTSetup secretly called before this
int main()
{
return asmMain();
}
and in assembly your main
function is now called asmMain
which will run after _mainCRTSetup
so something like this in assembly:
bits 64
global asmMain
asmMain:
mov rax, 69 ; some return code, 0 if no error but 69 is funny
ret
hope this was helpful, but this issue is pretty old so I'm sure you've figured it out yourself by now
@Zman2024 Tried your simple application, but having the same issue.

main.cpp
extern "C" int asmMain();
int main()
{
return asmMain();
}
asmmain.asm
[BITS 64]
GLOBAL asmMain
asmMain:
mov rax, 69
ret
Any ideas what could be wrong?
@Zman2024 Tried your simple application, but having the same issue.
![]()
main.cpp
extern "C" int asmMain(); int main() { return asmMain(); }
asmmain.asm
[BITS 64] GLOBAL asmMain asmMain: mov rax, 69 ret
Any ideas what could be wrong?
it seems like your main.cpp
and asmmain.asm
object files aren't linking to each other for some reason
I ran into a similar issue. everything looked correct with dumpbin -symbols .\assemblyNasm64.obj but could not get it to link in visual studio 2019 I changed global get_assembly_test_num ; makes this visible to linker
get_assembly_test_num: mov rax,1234 ; just return a constant ret to section .text ; required or visual studio will not link the function
global get_assembly_test_num ; makes this visible to linker
get_assembly_test_num: mov rax,1234 ; just return a constant ret
and then it linked you must give it a section or it will not link in visual studio Also note. if win32 the function requires a leading _ whereas win64 does not