I am trying to write a program, which adds 2 numbers, but I have problem with linking. The code compiles well, but I did not find any .lib file for the printf. As I know, some previuos MSVS had it in msvcrt.lib
, but where is it in MSVS 2019?
Code:
.686
.model flat, c
.data
format_str db "%d", 0Dh, 0Ah, 0
.code
printf proto c :dword, :vararg
AddFun:
push ebp
mov ebp, esp
sub esp, 8
mov eax, [ebp + 8]
add eax, [ebp + 12]
mov esp, ebp
pop ebp
ret
main proc
push 1
push 2
call AddFun
add esp, 8
invoke printf, offset format_str, eax
ret
main endp
end
Compile with
ml /c main.asm
Result
Microsoft (R) Macro Assembler Version 14.22.27905.0
Copyright (C) Microsoft Corporation. All rights reserved.
Assembling: main.asm
Link with
link main.obj /entry:main /subsystem:console
gives me
Microsoft (R) Incremental Linker Version 14.22.27905.0
Copyright (C) Microsoft Corporation. All rights reserved.
main.obj : error LNK2019: unresolved external symbol _printf referenced in function _main
So,
link main.obj /entry:main /subsystem:console msvcrt.lib
also does not work
I tried to link with legacy_stdio_definitions.lib
as some answer in the possible duplicates suggests, but it gave me a lot of new unresolved external symbols
___acrt_iob_func referenced in function __vwprintf_l
___stdio_common_vfwprintf referenced in function __vfwprintf_l
...