我试图在Windows上将C程序编译成ELF格式,因此我尝试做以下几件事:
output
gcc -Wall -c test.c -o test.o
编译,但没有作为MinGW https://github.com/nativeos/i386-elf-toolchain/releases ( 32位版本)进行测试,而是用"[...]/i386-elf-gcc" -c test.c -o test.o
编译,但我得到了错误i386-elf-gcc/libexec/gcc/i386-elf/5.2.0/cc1.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory
我要做的是在这里学习本教程:https://github.com/cfenollosa/os-tutorial,但我只能在汇编和C之间建立实际的链接。我很清楚,本教程是为Linux而不是Windows编写的,但我只是.这么说吧,我在使用Linux时遇到了麻烦。
我不知道需要哪些文件来解决我的问题,下面是:
void my_function() {
}
int main() {
return 0;
}
[bits 32]
[extern main]
call main
jmp $
[org 0x7c00]
kernel_offset equ 0x1000
mov [bootDrive], dl
mov bp, 0x9000
mov sp, bp
call switch_to_pm
call BEGIN_PM
jmp $
%include "gdt_init.asm"
%include "switch_32.asm"
bootDrive db 0
[bits 32]
BEGIN_PM:
call clear_screen
call kernel_offset
mov ebx, errorMSG
call print_string_pm
jmp $
%include "io/clear.asm"
%include "io/print.asm"
errorMSG db "Something went terribly wrong. Restart the PC to fix it", 0
; bootsector
times 510-($-$$) db 0
dw 0xaa55
其他文件几乎是复制粘贴,所以我不认为有必要包含它们。
发布于 2021-01-16 23:47:44
所以,这有点复杂,所以系好安全带。
首先,我使用了NASM和MinGW。下面列出了我的以下操作:
在gcc -m32 -c kernel.c -o kernel.o -ffreestanding -nostdlib -nostdinc
ld -m i386pe -o kernel.tmp -Ttext 0x1000 kernel_entry.o kernel.o
objcopy -O binary -j .text kernel.tmp kernel.bin
type bootsect.o kernel.bin > drive.bin
编译kernel.bin之后,
nasm kernel_entry.asm -f elf32 -o kernel_entry.o
https://stackoverflow.com/questions/65752272
复制相似问题