0
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

Lay González
  • 2,901
  • 21
  • 41
  • Please supply a minimal code example that shows this behaviour. It's also useful with information about compiler and OS together with the way you compile the code. – HonkyTonk Feb 05 '13 at 23:52

2 Answers2

6

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.

P.P
  • 117,907
  • 20
  • 175
  • 238
2

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.

Community
  • 1
  • 1
D.Shawley
  • 58,213
  • 10
  • 98
  • 113
  • At compiling or at linking? – Lay González Feb 06 '13 at 00:01
  • Compiling. Hopefully the additional verbosity will provide some insight into what is going on. More code might help too. – D.Shawley Feb 06 '13 at 00:02
  • I got this error in addition: Number.c:104:9: warning: ISO C90 forbids mixed declarations and code [-pedantic] – Lay González Feb 06 '13 at 00:07
  • line 104 is just: int i = 0; Is inside and if, that matters? – Lay González Feb 06 '13 at 00:08
  • In C90 (unlike C++ and C99), all declarations must be before all statements within the nearest enclosing `{ ... }` block. The easiest way to get rid of this complaint is to add `-std=gnu99` to your compile lines (right after the `-c`). – zwol Feb 06 '13 at 00:10
  • 1
    @D.Shawley You are clearly linking if (a) you get an error that mentions an address and (b) you are using the `-l` option. – user207421 Feb 06 '13 at 09:23
  • @EJP - the first comment was before I realized what the problem actually was and edited my answer – D.Shawley Feb 06 '13 at 18:50