【问题标题】:How Can I fix 'Makefile:6: *** missing separator. Stop'.?如何修复'Makefile:6:***缺少分隔符。停止'。?
【发布时间】:2021-10-11 16:41:05
【问题描述】:
all: elfparser

elfparser: disasm.o elf-parser.o elf-parser-main.o elf-program_read.o srec.o
    gcc -o elfparser disasm.o elf-parser.o elf-parser-main.o elf-program_read.o srec.o

elf-parser-main.o: elf-parser-main.c
    gcc -c -o elf-parser-main.o elf-parser-main.c

disasm.o: disasm.c
    gcc -c -o disasm.c

elf-parser.o: elf-parser.c
    gcc -c -o elf-parser.c

elf-program_read.o: elf-program_read.c
    gcc -c -o elf-program_read.c
    
srec.o: srec.c
    gcc -c -o srec.c

clean:
    rm -rf *o elfparser

【问题讨论】:

  • tabs 和 new lines 在 Makefile 中很重要。我将编辑您的问题,此外,您的 make 文件在生成 .o 文件时还有其他问题。
  • 这不能与您遇到此错误的生成文件相同,因为这里第 6 行没有错误,正如问题标题所述。然而,这个错误是人们在编写 makefile 时遇到的最常见的问题:在 Internet 上搜索此错误消息会为您提供大量有关问题所在的信息...

标签: makefile


【解决方案1】:

This question is already VERY NICELY although slightly differently answered here

这是一个稍微好一点的方法:


BIN=elfparser
SRC=disasm.c elf-parser.c elf-parser-main.c elf-program_read.c srec.c

# OBJ filenames are created from SRC filenames by replacing .c with .o
OBJ=$(SRC:%.c=%.o)

CC=gcc
CFLAGS=-O2 -g

default: $(BIN)

# To create the binary, build all objects first
$(BIN): $(OBJ)
        $(CC) -o $@ $(OBJ) 

# How to generate a .o from a .c rule:
%.o: %.c
        $(CC) $(CFLAGS) $(INCLUDES) -o $@ -c %< 


如果您决定剪切和粘贴此代码,请记住规则下的行(即在 shell 中运行以完成工作的命令)必须有一个 (不是空格)。

【讨论】:

  • 谢谢,艾哈迈德·马苏德
猜你喜欢
  • 2022-01-05
  • 2023-03-21
  • 1970-01-01
  • 2017-08-07
  • 2014-07-18
  • 2019-02-06
  • 2022-01-20
  • 2013-09-26
相关资源
最近更新 更多