Makefile在c中找不到函数

Makefile在c中找不到函数,c,makefile,C,Makefile,我编写了以下makefile: CC = gcc OBJS = Car.o Guide.o GuideSystem.o DEBUG_OBJS = Car_debug.o Guide_debug.o GuideSystem_debug.o SOURCE = Car.c Guide.c GuideSystem.c HEADER = Car.h Guide.h GuideSystem.h list.h set.h CFLAGS = -std=c99 -Wall -pedantic-errors -We

我编写了以下makefile:

CC = gcc
OBJS = Car.o Guide.o GuideSystem.o
DEBUG_OBJS = Car_debug.o Guide_debug.o GuideSystem_debug.o
SOURCE = Car.c Guide.c GuideSystem.c
HEADER = Car.h Guide.h GuideSystem.h list.h set.h
CFLAGS = -std=c99 -Wall -pedantic-errors -Werror
LIBM = -L. -lib
EXEC = test.exe test1.exe test2.exe test2_debug.exe
TEST_O = test1.o test2.o test2_debug.o test.o

#make test1.exe
test1.exe : $(OBJS) test1.o
    $(CC) $(CFLAGS) -DNDEBUG $(OBJS) test1.o $(LIBM) -o $@

#make test2.exe
test2.exe : $(OBJS) test2.o
    $(CC) $(CFLAGS) -DNDEBUG $(OBJS) test2.o $(LIBM) -o $@

#make test2_debug.exe
test2_debug.exe : $(OBJS) test2_debug.o
    $(CC) $(CFLAGS) -g $(OBJS) test2_debug.o $(LIBM) -o $@

#make test.exe
test.exe : $(OBJS) test.o
    $(CC) $(CFLAGS) -DNDEBUG $(OBJS) test.o $(LIBM) -o $@

#Testing (no asserts)
test.o : test.c Guide.h GuideSystem.h
    $(CC) -c -DNDEBUG $*.c $(CFLAGS)
test1.o : test1.c Guide.h GuideSystem.h
    $(CC) -c -DNDEBUG $*.c $(CFLAGS)
test2.o : test2.c Guide.h GuideSystem.h
    $(CC) -c -DNDEBUG $*.c $(CFLAGS)
Guide.o : Guide.c Guide.h list.h Car.h
    $(CC) -c -DNDEBUG $*.c $(CFLAGS)
GuideSystem.o : GuideSystem.c GuideSystem.h set.h
    $(CC) -c -DNDEBUG $*.c $(CFLAGS)
Car.o : Car.h
    $(CC) -c -DNDEBUG $*.c $(CFLAGS)

#Debug testing
test2_debug.o : test2.c Guide.h GuideSystem.h
    $(CC) -c -g $(CFLAGS) test2.c -o $@
Guide_debug.o : Guide.c Guide.h list.h Car.h
    $(CC) -c -g $(CFLAGS) Guide.c -o $@
GuideSystem_debug.o : GuideSystem.c GuideSystem.h set.h
    $(CC) -c -g $(CFLAGS) GuideSystem.c -o $@
Car_debug.o : Car.h
    $(CC) -c -g $(CFLAGS) Car.c -o $@

#Clean builds
clean :
    rm -f $(OBJS) $(DEBUG_OBJS) $(EXEC) $(TEST_O)
当我运行
make test
时,我得到:

gcc   test.o   -o test
test.o: In function `main':
test.c:(.text+0x29): undefined reference to `createGuide'
... more undefined functions
我对makefile有一些问题,但似乎找不到问题。所有其他
make
选项正常工作,只有
make test
失败

据我所知,它应该运行:

gcc -c -DNDEBUG -std=c99 -Wall -Werror -pedantic-errors test.c
gcc -o test.exe -DNDEBUG Guide.o GuideSystem.o Car.o test.o -L. -lib

有什么问题吗?我怎样才能解决它?我的makefile有问题吗?

您没有定义任何
test
目标,因此
make
错误地猜测您只是想从
test.o
(隐式规则)生成名为
test
的程序

您可能应该在
Makefile
中插入以下内容:

test: test.exe test2.exe
    ./test.exe
    ./test2.exe
.PHONY: test


测试目标在哪里?我认为您在这里遇到了一个隐式规则,
make
假设您想从
test.o
生成一个名为
test
的二进制文件。如果您想构建您在makefile中定义的
test.exe
目标,您应该运行
make test.exe
。您无法运行
maketest
,因为(正如hmm所说)您没有定义名为
test
的目标。