编译器说,即使我使用-lm链接,但未定义pow,但编译时

Lay*_*lez 0 c compiler-construction linker math.h

value *= pow(10, 3); // this one compiles
value *= pow(10, aVar); // this one produces this error:
                         //Number.c:(.text+0x469): undefined reference to `pow'
Run Code Online (Sandbox Code Playgroud)

aVar是一个int变量.

会是什么呢?

我正在使用makefile.我很喜欢"make lexanc"我的makefile看起来像这样:

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
...
Run Code Online (Sandbox Code Playgroud)

我的cc版本是:laygr @ xxx $ cc --version cc(Ubuntu/Linaro 4.6.3-1ubuntu5)4.6.3

P.P*_*.P. 6

库应该在编译选项中的所有对象之后.将其更改为:

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
Run Code Online (Sandbox Code Playgroud)

注意-lm已移至最后.