c - 在同一个 makefile 中制作 C 和 ASM 文件失败

标签 c linux assembly makefile cross-compiling

我已经编写了一个 Makefile 来从 ASM 和 C 源代码生成内核镜像,但是它无法编译 C 源代码。我认为错误在于使用两个对象列表,一个用于 ASM,一个用于 C。如果该文件还有其他问题,请随时告诉我。

终端输出

arm-none-eabi-as -I source/ source/maths.s -o build/maths.o
arm-none-eabi-as -I source/ source/tags.s -o build/tags.o
make: *** No rule to make target 'build/firstCFile.o', needed by 'build/output.elf'.  Stop.

生成文件

# The toolchain to use. arm-none-eabi works, but there does exist 
# arm-bcm2708-linux-gnueabi.
ARMGNU ?= arm-none-eabi

# The intermediate directory for compiled object files.
BUILD = build/

# The directory in which source files are stored.
SOURCE = source/

# The name of the output file to generate.
TARGET = bin/kernel.img

# The name of the assembler listing file to generate.
LIST = bin/kernel.list

# The name of the map file to generate.
MAP = bin/kernel.map

# The name of the linker script to use.
LINKER = kernel.ld

# The names of libraries to use.
LIBRARIES := csud

# The names of all object files that must be generated. Deduced from the 
# assembly code files in source.
OBJECTS := $(patsubst $(SOURCE)%.s,$(BUILD)%.o,$(wildcard $(SOURCE)*.s))

OBJECTS2 := $(patsubst $(SOURCE)%.c,$(BUILD)%.o,$(wildcard $(SOURCE)*.c))

# Rule to make everything.
all: $(TARGET) $(LIST)

# Rule to remake everything. Does not include clean.
rebuild: all

# Rule to make the listing file.
$(LIST) : $(BUILD)output.elf
    $(ARMGNU)-objdump -d $(BUILD)output.elf > $(LIST)

# Rule to make the image file.
$(TARGET) : $(BUILD)output.elf
    $(ARMGNU)-objcopy $(BUILD)output.elf -O binary $(TARGET) 

# Rule to make the elf file.
$(BUILD)output.elf : $(OBJECTS) $(OBJECTS2) $(LINKER)
    $(ARMGNU)-ld --no-undefined $(OBJECTS) $(OBJECTS2) -L. $(patsubst %,-l %,$(LIBRARIES)) -Map $(MAP) -o $(BUILD)output.elf -T $(LINKER)

# Rule to make the object files.
$(BUILD)%.o: $(SOURCE)%.s
    $(ARMGNU)-as -I $(SOURCE) $< -o $@

$(BUILD):
    mkdir $@

最佳答案

我认为您需要从 c 源代码制定规则:

$(BUILD)%.o : $(SOURCE)%.c 
    $(ARMGNU)-gcc -c -I $(SOURCE) $< -o $@

关于c - 在同一个 makefile 中制作 C 和 ASM 文件失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48218537/

相关文章:

c - 在服务器处理 UDP 数据包流

linux - unix - 剪切命令(添加自己的定界符)

c - 如何在 linux 内核中隐藏/取消隐藏 'ls -a' 的文件?

c - 结构和动态数组

python脚本检测热插拔事件

c - C 和汇编中的 goto 语句是否会破坏引用局部性从而降低性能?

assembly - ARM 汇编中 32 位字内的高效按字节循环

assembly - 为什么x86-64/AMD64 System V ABI要求16字节堆栈对齐?

c - 修改作为参数传递的* int []

c - 解析配置文件中带有前导和终止空格的简单名称/值对设置 - C