OSDev - 在 'docker' 中使用 'make' 命令时出错
OSDev - Error when using the 'make' command in 'docker'
我开始使用 this video 中的教程编写 OS 内核。我已经写了 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
编译器?
(我的开发 OS 是 Ubuntu 20.04.2.0 LTS。)
当我在 makefile
中使用 ld
命令而不是 x86_64-elf-ld
命令时,一切正常,而且我没有使用 docker
来编译我的项目。
如果有任何更好的解决方案,包括从 docker
编译文件,请写信给我。
谢谢!
我开始使用 this video 中的教程编写 OS 内核。我已经写了 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
编译器?
(我的开发 OS 是 Ubuntu 20.04.2.0 LTS。)
当我在 makefile
中使用 ld
命令而不是 x86_64-elf-ld
命令时,一切正常,而且我没有使用 docker
来编译我的项目。
如果有任何更好的解决方案,包括从 docker
编译文件,请写信给我。
谢谢!