未定义的引用`pow' - makefile

时间:2015-12-23 15:39:29

标签: c makefile linker

使用makefile构建程序时遇到问题。

运行make后我收到错误:

ScanData.o: In function `CheckGrade':
ScanData.c:(.text+0x1ef): undefined reference to `pow'

这是makefile:

a.out: Update.o ScanData.o ReallocAndFree.o PrintStudentMaxGrade.o PrintAllStudents.o DeleteStudent.o AddStudent.o AddOrUpdate.o main.o
 gcc Update.o ScanData.o ReallocAndFree.o PrintStudentMaxGrade.o PrintAllStudents.o DeleteStudent.o AddStudent.o AddOrUpdate.c main.o

AddOrUpdate.o: AddOrUpdate.c AddOrUpdate.h
    gcc -c AddOrUpdate.c

AddStudent.o: AddStudent.c AddStudent.h
    gcc -c AddStudent.c

DeleteStudent.o: DeleteStudent.c DeleteStudent.h
    gcc -c DeleteStudent.c

PrintAllStudents.o: PrintAllStudents.c PrintAllStudents.h
    gcc -c PrintAllStudents.c

PrintStudentMaxGrade.o: PrintStudentMaxGrade.c PrintStudentMaxGrade.h
    gcc -c PrintStudentMaxGrade.c

ReallocAndFree.o: ReallocAndFree.c ReallocAndFree.h
    gcc -c ReallocAndFree.c

ScanData.o: ScanData.c ScanData.h
    gcc -c ScanData.c -lm

Update.o: Update.c Update.h
    gcc -c Update.c

main.o: main.c AddOrUpdate.c AddStudent.c DeleteStudent.c PrintAllStudents.c PrintStudentMaxGrade.c ReallocAndFree.c ScanData.c Update.c
    gcc -c main.c

谢谢。

1 个答案:

答案 0 :(得分:1)

pow是一个stdlib函数,但要使用它,你应该链接stdlib本身(math lib)。

通常gcc会自动执行此操作,但请尝试添加-lm链接标记:

gcc -lm Update.o ScanData.o <..the rest of object files..>

还要确保系统中存在libc(在debian / ubuntu上 - dpkg -s libc6-dev应该告诉它已安装)

与问题没有直接关系: main.o真的取决于所有来源吗?它只从main.c

构建
相关问题