c - Makefile 在 c 中找不到函数
问题描述
我写了以下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
仅命名为 from test.o
(implicit rule) 的程序。
您可能应该插入的Makefile
是:
test: test.exe test2.exe
./test.exe
./test2.exe
.PHONY: test
推荐阅读
- mongodb - Robo 3T:在将集合导出到 JSON 时填充 Javascript 函数调用的实际值
- javascript - 安装模块与使用其 url 包含模块之间的主要区别是什么?
- php - PHP:如何“空”一个类结果
- amazon-s3 - PIXI.JS:将 Origin 从 API Gateway 切换到 NGINX 后 Cloudfront+S3 出现 CORS 问题
- c++ - C++ 中的 HackerRank 大排序分段错误
- javascript - 为 WebDriver.IO 页面对象传入一个变量而不是静态字符串
- typescript - 如何在按钮单击时禁用 p5 画布
- sass - 从 Sass 映射中获取数字而不是字符串
- reactjs - 我想在 Laravel 项目中使用 TypeScript 和 React
- python - Dataframe groupby 计算频率并写入 Excel