我有一套在testhelper.c中定义的辅助函数。为了方便它们的使用,我试图将它们链接到头文件testhelper.h并将这个文件包含在我正在开发的测试程序中。但是,文件没有正确链接,因为我在编译时会在测试程序中获得“未定义的引用”。
makefile中的代码是:
randomtestadventurer: randomtestadventurer.c dominion.o rngs.o testhelpers.o
gcc -o randomtestadventurer -g randomtestadventurer.c dominion.o rngs.o $(CFLAGS)
randomtestcard: randomtestcard.c dominion.o rngs.o testhelpers.o
gcc -o randomtestcard -g randomtestcard.c dominion.o rngs.o $(CFLAGS)
testhelpers.o: testhelpers.h testhelpers.c
gcc -c testhelpers.c -g $(CFLAGS)
两个随机测试程序中的包含路径是: #include“testhelpers.h”
这是我第一次尝试从头开始制作的头文件,所以我不确定我做错了什么。
答案 0 :(得分:0)
你写的makefile似乎有些错误:
randomtestadventurer: randomtestadventurer.o dominion.o rngs.o testhelpers.o
gcc -o randomtestadventurer -g randomtestadventurer.o dominion.o rngs.o testhealpers.o $(CFLAGS)
randomtestcard: randomtestcard.o dominion.o rngs.o testhelpers.o
gcc -o randomtestcard -g randomtestcard.o dominion.o rngs.o testhelpers.o $(CFLAGS)
randomtestadventurer.o : randomtestadventurer.c
gcc -o randomtestadventurer.o -c -Wall randomtestadventurer.c header.h
randomtestcard.o : randomtestcard.c
gcc -o randomtestcard.o -c -Wall randomtestcard.c header.h
testhelpers.o: testhelpers.h testhelpers.c
gcc -c testhelpers.c -g $(CFLAGS)
你也必须给出制作dominion.o和rngs.o的规则。代替header.h使用您实际包含在文件中的标题