使用链接器“ld”在asm文件中执行cpp过程

问题描述 投票:0回答:1

我从系统编程开始,但我遇到了令人讨厌的情况。我不知道如何使用nasm和g ++编译器在asm文件中运行cpp过程。

这是我在asm中的代码,名为kernel.asm:

[BITS 32]

EXTERN scrollup, print
global _start

_start :
    mov ax , msggdt
    push ax
    call print
    pop ax

    mov ax , msggdt32
    push ax
    call print
    pop ax

    mov ax , 3
    push ax
    call scrollup
    pop ax



end:
    jmp end

msggdt : db "Load gdt",13 , 10,0
msggdt32 : db "Load protected mode",13,10,0

我的cpp文件包含print,scrollup等函数

我指定了我的编译器版本:NASM版本2.14和gcc版本8.2.0(Debian 8.2.0-21)

g++ -c screen.cpp
screen.cpp: In function ‘void _putcar_(uchar)’:
screen.cpp:63:59: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
   video = (unsigned char*) (RAMSCREEN + 2 * kX + 160 * kY ) ;

nasm -f elf64 -o kernel.o kernel.asm

现在,看,我已经尝试了4次LD的调用,不仅改变了对象的顺序,而且还改变了输出,但什么也没有

ld --oformat binary -Ttext 1000 screen.o kernel.o  -o screen
ld: kernel.o: in function `_start':
kernel.asm:(.text+0x7): undefined reference to `print'
ld: kernel.asm:(.text+0x14): undefined reference to `print'
ld: kernel.asm:(.text+0x21): undefined reference to `scrollup'


ld --oformat binary -Ttext 1000 screen.o kernel.o  -o kernel
ld: kernel.o: in function `_start':
kernel.asm:(.text+0x7): undefined reference to `print'
ld: kernel.asm:(.text+0x14): undefined reference to `print'
ld: kernel.asm:(.text+0x21): undefined reference to `scrollup'

ld --oformat binary -Ttext 1000 kernel.o  screen.o -o kernel
ld: kernel.o: in function `_start':
kernel.asm:(.text+0x7): undefined reference to `print'
ld: kernel.asm:(.text+0x14): undefined reference to `print'
ld: kernel.asm:(.text+0x21): undefined reference to `scrollup'

ld --oformat binary -Ttext 1000 kernel.o  screen.o -o screen
ld: kernel.o: in function `_start':
kernel.asm:(.text+0x7): undefined reference to `print'
ld: kernel.asm:(.text+0x14): undefined reference to `print'
ld: kernel.asm:(.text+0x21): undefined reference to `scrollup'

拜托,我需要一些帮助。如果我犯了一些错误,抱歉,请告诉我。

谢谢

c++ g++ x86-64 nasm osdev
1个回答
0
投票

我可以建立链接。但是,我用过:

gcc -c screen.c
nasm -f elf64 -o kernel.o kernel.asm

所以我必须有一个c文件而不是c ++ ..我不明白为什么。有人可以向我解释它为什么有效吗?

© www.soinside.com 2019 - 2024. All rights reserved.