2

I have include the math.h in my c file, however it keeps prompts undefined reference to truncand undefined reference to ceil. And I didn't even use trunc in my file. Could anyone tell what was the problem?

Blake
  • 7,367
  • 19
  • 54
  • 80
  • 6
    Possibly you're using gcc and have forgotten to link to libm.a by adding `-lm` to your command line? Its hard to say when you don't include any code or a note of your build command. – simonc Nov 17 '13 at 23:16
  • Are you getting complaints from the compiler or the linker? It looks to me like the compiler, though other folks here have answered how to make the linker link with the math library (`-lm`). What compiler are you using? – kmort Nov 18 '13 at 02:46

2 Answers2

5

If you compile using gcc, you might need to add -lm option to link to the math library (libm) like

gcc test.c -lm
yulian
  • 1,601
  • 3
  • 21
  • 49
Andrei B
  • 2,740
  • 17
  • 12
1

It seems that you will need the info about how C source code are compiled and linked together. The link contains some basic info: Compile & Link

You use -I option of gcc to specify where to find headers, and -l option to link standard libraries

Community
  • 1
  • 1
raof01
  • 76
  • 3