我的makefile找不到头文件

时间:2014-05-07 17:50:21

标签: gcc makefile

我写了一个简单的makefile

 1 LIBS= -L /usr/local/pgsql/lib
 2 INCL= -I /usr/local/pgsql/include -I/home/name/
 3 
 4 pg: pg.o
 5     gcc -o  pg pg.o  $(LIBS) -lpq
 6 
 7 pg.o: pg.c
 8     gcc -c $(INCL) $(LIBS) pg.c

在name文件夹下,有三个文件:pg.c,timer.c,timer.h 但它报告错误无法找到时间功能。我的makefile有什么问题?谢谢。 错误是

 gcc -o  pg pg.o  -L /usr/local/pgsql/lib -lpq
 pg.o: In function `main':
 pg.c:(.text+0x91): undefined reference to `createTimer'
 pg.c:(.text+0xa1): undefined reference to `startTimer'
 pg.c:(.text+0x167): undefined reference to `endTimer'
 ...
 pg.c:(.text+0x214): undefined reference to `displayTimer'
 pg.c:(.text+0x220): undefined reference to `destroyTimer'
 collect2: error: ld returned 1 exit status
 make: *** [pg] Error 1

1 个答案:

答案 0 :(得分:1)

您还没有给我们足够的信息以确定,但将timer.o添加到pg规则的先决条件列表中可能就足够了:

pg: pg.o timer.o
    gcc -o pg $^ $(LIBS) -lpq