test platform is windows 32bit.
So basically I want to assembly + link a snippet of assembly code in these commands:
nasm -fwin32 test.s
cl test.obj /link msvcrt.lib
It says :
error LNK2001: unresolved external symbol printf
In my code I do have function call like this:
call printf
So I changed all of these into
call _printf
and it works.
I am not familiar with programming on windows, but is there any way to resolve the external symbol of printf ?
Because I am doing some automatically transform task, and transformation of all the function calls with _ begin should be very tedious...
Can anyone give me some help..? Thank you!
MSVCRT, like everything compiled with Visual C++, exports
cdecl
functions using an underscore prefix. For your own libraries, you can override this behaviour, but since MSVCRT is not your library, you can't change that.You really are going to have to make your assembly calls use the underscore name. But nasm has an option,
--prefix
, which makes this easier:--prefix _
. (Thanks to Frank Kotler for mentioning this.)