我正在尝试开始使用 CuTest 在 C 中进行单元测试。
make-ing时出现如下错误:
dev:~/bistro# make
cutest/CuTest.c:10: *** missing separator. Stop.
文件 cutest/CuTest.c
直接来自库。我没有对它进行任何修改。以下是相关行:
08 - #include "CuTest.h"
09 -
10 - /*-------------------------------------------------------------------------*
11 - * CuStr
12 - *-------------------------------------------------------------------------*/
13 -
14 - char* CuStrAlloc(int size)
这是我正在使用的 Makefile,以供完整引用:
NAME = bistro
SOURCES_DIR = src
OBJECTS_DIR = obj
SOURCES = $(shell find $(SOURCES_DIR) -type f -name *.c) cutest/CuTest.c
OBJECTS = $(patsubst $(SOURCES_DIR)/%.c, $(OBJECTS_DIR)/%.o, $(SOURCES))
DEPS = $(OBJECTS:.o=.d)
CFLAGS = -Wall -Werror -Wextra
COMPILER = gcc -I cutest -I $(SOURCES_DIR) $(CFLAGS)
BISTRO_MAIN = $(OBJECTS_DIR)/bistro/bistro_main.o
.PHONY: test all clean fclean re
all: $(NAME)
# header dependencies
-include $(DEPS)
$(NAME): $(OBJECTS)
$(COMPILER) -o $(NAME) $(OBJECTS)
test: $(filter-out $(BISTRO_MAIN), $(OBJECTS))
$(COMPILER) -c all_tests.c -o all_tests.o
$(COMPILER) -o test $(filter-out $(BISTRO_MAIN), $(OBJECTS)) all_tests.o
rm -f all_tests.o
$(OBJECTS_DIR)/%.o: $(SOURCES_DIR)/%.c
@if [ ! -d "$(@D)" ]; then mkdir -p $(@D); fi
$(COMPILER) -MMD -c $< -o $@
clean:
rm -Rf $(OBJECTS_DIR)/*
fclean: clean
rm -f $(NAME)
re: fclean all
出现此错误消息的原因可能是什么?
编辑 1: makefile 只缩进了 4 个空格的制表符。对“查找”命令的调用可能是造成这种情况的原因吗?另外,为什么错误说缺少分隔符在 .c 文件中?
编辑 2: 已接受的答案显示了错误。此外,调用没有成功,因为它正在搜索 *.c
,应该是 "*.c"
。
最佳答案
这意味着您正在使用(四个)空格而不是 tab
符号。
Make 目标的命令必须用 tab
缩进。
参见 http://www.gnu.org/software/make/manual/make.html#Rule-Introduction :
Please note: you need to put a tab character at the beginning of every recipe line! This is an obscurity that catches the unwary. If you prefer to prefix your recipes with a character other than tab, you can set the .RECIPEPREFIX variable to an alternate character
你的错误是因为你在 Makefile 中包含了一个 C 源文件。
SOURCES = $(shell find $(SOURCES_DIR) -type f -name *.c) cutest/CuTest.c
OBJECTS = $(patsubst $(SOURCES_DIR)/%.c, $(OBJECTS_DIR)/%.o, $(SOURCES)) # cutest/CuTest.c stays cutest/CuTest.c
DEPS = $(OBJECTS:.o=.d)
-include $(DEPS) # oops, includes cutest/CuTest.c
关于makefile - Make 表示 "missing separator"来自 CuTest 的源 .c 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18211616/