You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Makefile缺失分隔符错误及编译问题的排查与解决

Makefile语法错误排查与修正

问题1:分隔符缺失错误

最初编写Makefile时遇到如下语法错误:

Makefile:16: *** missing separator.  Stop.

对应的最小可复现Makefile代码:

TARGET=ice
CC=gcc

SOURCES = \
    src/main.c \
    driver/driver.c \

INCLUDES=\
    -Iinclude \

OBJECTS = $(SOURCES:.c=.o)

all: $(TARGET)

$(TARGET): $(OBJECTS)
    $(CC) -o $@ $^

%.o: %.c
    $(CC) $(INCLUDES) -c $@ -o $<

clean:
    rm $(TARGET)

.PHONY: all good clean

问题2:编译阶段错误

改用gedit替代Sublime 3编写后,分隔符问题解决,但出现新的编译错误:

[root][ice] $ make
gcc -Iinclude  -c src/main.o -o src/main.c
gcc: error: src/main.o: No such file or directory
gcc: fatal error: no input files
compilation terminated.
Makefile:19: recipe for target 'src/main.o' failed
make: *** [src/main.o] Error 1

最终修正方案

只需将.o目标的编译规则修改为:

%.o: %.c
    $(CC) $(INCLUDES) -c -o $@ $<

内容的提问来源于stack exchange,提问作者IceMarek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 16:25:11