value *= pow(10, 3); // this one compiles
value *= pow(10, aVar); // this one produces this error:
//Number.c:(.text+0x469): undefined reference to `pow'
aVar 是一个整型变量。
它会是什么?
我正在使用生成文件。 我正在执行“make lexanc” 我的生成文件如下所示:
lexanc: lexandr.o lexanc.o scanner.o printtoken.o token.h lexan.h Number.o
cc -o lexanc -lm lexandr.o lexanc.o scanner.o printtoken.o Number.o
...
Number.o: Number.c Number.h lexan.h
cc -c Number.c
lexanc.o: lexanc.c token.h lexan.h Number.h
cc -c lexanc.c
...
我的抄送版本是: laygr@xxx$ 抄送 --version cc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
最佳答案
库应该在编译选项中的所有对象之后。将其更改为:
lexanc: lexandr.o lexanc.o scanner.o printtoken.o token.h lexan.h Number.o
cc -o lexanc lexandr.o lexanc.o scanner.o printtoken.o Number.o -lm
注意 -lm
已移至末尾。
关于编译器说 pow 是未定义的,即使我正在链接 -lm,但编译时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14719128/