Question

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 is an int variable.

What could it be?

I'm using a makefile. I'm excecuting "make lexanc" My makefile looks like this:

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
...

My cc version is: laygr@xxx$ cc --version cc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

Was it helpful?

Solution

Libraries should come after all the objects in the compiling option. Change it to:

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

Note -lm has been moved to the end.

OTHER TIPS

Are you including math.h? Try adding -Wall -ansi -pedantic as command line arguments to the C compiler. There is usually a definition of CFLAGS somewhere for this purpose.

EDIT
This is actually a common problem that I had completely forgotten about. Move the -lm to the end of the parameter list. More specifically, it needs to be after all of the objects. Take a look at answers to this question for more details.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top