Click to See Complete Forum and Search --> : Math.h compiling but not linking


.t3
03-05-2003, 09:17 AM
I have a snippet of code written in C, everything works like a charm except the linking.
Every function I try to use from math.h gets throught the compiler but not the linker.

truls
03-05-2003, 10:45 AM
Maybe linking with the math library would help? :p
If I don't remember wrong you use the compiler directive -lm (small L) to link with the math library.

In other words:
gcc myprog.c -o myprog -lm

T.

bigrigdriver
03-06-2003, 02:42 PM
At the top of your code, try adding this to your includes: #include <math.h>

truls
03-07-2003, 04:07 AM
Since he mentioned the linker, the includes cannot be the problem can they? I thought it was the compiler step that would fail if you were missing includes, and the linker step that would fail if you were missing libraries. Or am I wrong?

divakar
03-07-2003, 04:27 AM
Truls is right. Use -lm on the compile command line. I have recently solved the same linking problem using the explicit link library option for gcc 2.95. As I understand, gcc will link in the libm.a library for math support.

f4_yellowjacket
03-07-2003, 12:58 PM
Has it worked for you yet .t3?

If not try this

gcc -o myprog -c source.c