【问题标题】:OSDev - Error when using the 'make' command in 'docker'OSDev - 在“docker”中使用“make”命令时出错
【发布时间】:2021-09-08 00:43:21
【问题描述】:

我开始使用this video 中的教程编写操作系统内核。我已经写了Makefile,你可以在这里看到:

x86_64_asm_source_files := $(shell find src/impl/x86_64 -name *.asm)  # Holds the list of all of the assembly source files.
x86_64_asm_object_files := $(patsubst src/impl/x86_64/%.asm, build/x86_64/%.o, $(x86_64_asm_source_files))  # Holds the list of all of the obj files.

# Define the command we need to run to build one of the object files from the source files:
$(x86_64_asm_object_files): build/x86_64/%.o : src/impl/x86_64/%.asm
# For compiling the assembly files:
    mkdir -p $(dir $@) && \
    nasm -f elf64 $(patsubst build/x86_64/%.o, src/impl/x86_64/%.asm, $@) -o $@

# Create a custom phony command:
.PHONY: build-x86_64

# Run only if any of the object files have been changed:
build-x86_64: $(x86_64_asm_object_files)
# For generating the '.iso' file:
    mkdir -p dist/x86_64 && \
    x86_64-elf-ld -n -o dist/x86_64/kernel.bin -T targets/x86_64/linker.ld $(x86_64_asm_object_files) && \
    cp dist/x86_64/kernel.bin targets/x86_64/iso/boot/kernel.bin && \
    grub-mkrescue /usr/lib/grub/i386-pc -o dist/x86_64/kernel.iso targets/x86_64/iso

当我在 docker 容器中运行 make build-x86_64 时,我收到此错误:

make: *** No rule to make target 'build-x86_64'.  Stop.

当我只写make 命令时,由于这个错误,似乎没有makefile

make: *** No targets specified and no makefile found.  Stop.

当我在 docker 之外使用 make 命令时,我得到:

mkdir -p build/x86_64/boot/ && \
nasm -f elf64  src/impl/x86_64/boot/main.asm -o build/x86_64/boot/main.o
mkdir -p build/x86_64/boot/ && \
nasm -f elf64  src/impl/x86_64/boot/header.asm -o build/x86_64/boot/header.o
mkdir -p dist/x86_64 && \
x86_64-elf-ld -n -o dist/x86_64/kernel.bin -T targets/x86_64/linker.ld  build/x86_64/boot/main.o  build/x86_64/boot/header.o   && \
cp dist/x86_64/kernel.bin targets/x86_64/iso/boot/kernel.bin && \
grub-mkrescue /use/lib/grub/i386-pc -o dist/x86_64/kernel.iso targets/x86_64/iso
/bin/sh: 2: x86_64-elf-ld: not found
make: *** [Makefile:16: build-x86_64] Error 127

我用于构建 docker 本身的 docker 命令是:sudo docker build buildenv -t learnos-buildenv

我用于运行 docker 终端的 docker 命令是:sudo docker run --rm -it -v /root/env learnos-buildenv

我可以做些什么来修复docker?或者如何在不使用docker 的情况下获得x86_64-elf-ld 编译器?

(我的开发操作系统是 Ubuntu 20.04.2.0 LTS。)

【问题讨论】:

  • 你有一个错字。目标称为build-x86_64 而不是build-x86-64
  • 谢谢!但即便如此,我偷窃也有同样的问题。
  • 它在 docker 之外工作吗?
  • 我在 docker 之外尝试过,但编译器有问题:`nasm -f elf64 src/impl/x86_64/boot/header.asm -o build/x86_64/boot/header.o/bin/sh: 2: x86_64-elf-ld: not foundmake: *** [Makefile:16: build-x86_64] Error 127
  • 但是找到目标了吗?如果 make 在 docker 外部工作,请确保在 docker 内部,从正确的文件夹调用 make

标签: c linux docker osdev


【解决方案1】:

当我在makefile 中使用ld 命令而不是x86_64-elf-ld 命令时,一切正常,而且我没有使用docker 来编译我的项目。 如果有任何更好的解决方案,包括从docker 编译文件,请写信给我。

谢谢!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-18
    • 2021-02-08
    • 2015-10-21
    • 2018-11-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多