link.exe未链接到C运行时

时间:2019-10-18 19:13:28

标签: assembly nasm

我正在尝试在NASM(x86-64,Windows)下编译该程序。

; prime.asm
global _main
extern _scanf
extern _printf

section .data:
    n: dd 0
    i: dd 2
    format_string_scanf: db '%d', 0x0A
    format_string_no_printf: db 'The number %d is not prime', 0x0A
    format_string_yes_printf: db 'The number %d is prime', 0x0A

section .text
_main:
    push n
    push format_string_scanf
    call _scanf
    cmp dword [n], 1
    je NOT_PRIME
    cmp dword [n], 0
    je NOT_PRIME
FOR_LOOP:
    mov eax, [i]
    mul dword [i]
    cmp eax, [n]
    jg IS_PRIME
    mov edx, 0
    mov eax, [n]
    div dword [i]
    cmp edx, 0
    je NOT_PRIME
    jmp FOR_LOOP
IS_PRIME:
    push qword [n]
    push format_string_yes_printf
    call _printf
    jmp PROGRAM_END
NOT_PRIME:
    push qword [n]
    push format_string_no_printf
    call _printf
PROGRAM_END:
    ret

这些是我使用的选项:

nasm.exe -f win64 -o prime.obj prime.asm
link.exe prime.obj /subsystem:console /entry:_main

NASM很好,但是link.exe抛出2个错误:

prime.obj : error LNK2001: unresolved external symbol _scanf
prime.obj : error LNK2001: unresolved external symbol _printf
prime.obj : fatal error LNK1120: 2 unresolved externals

我想它无法以一种或另一种方式链接到C运行时。有人可以帮我解决这两个错误吗?

0 个答案:

没有答案