-   Linux - Newbie (
-   -   Need help with a c program (

jaggu 02-10-2004 02:21 PM

Need help with a c program
I am trying with a simple c program that uses a pow(op1, op2) function.
gcc says "undefined reference to pow" during linking.
"gcc -c myprog.c" gives no error messages (even when i didnt include math.h :-S ),
but gave the above error message on 'pow' when i gave "gcc myprog.c"

"man pow" says function 'pow' is with the 'math.h'.
But giving/not giving "#include <math.h>" have no effect with gcc.
Then i tried using some other functions with the math.h like log, exp, etc,
and i got the same error message "undefined reference to ___" with those functions too.
I checked the /usr/include directory and found math.h there. [I dint know what is its corresponding lib file]

I am with a redhat 8.0 linux box.
I also tried uninstalling and then re-installing all the development tools using the GUI package manager,
but no effect.:-(


jtshaw 02-10-2004 02:23 PM

Try doing this = "gcc -Wall -o myprog -lm myprog.c".

-Wall = shows all warnings
-o myprog = sets the name of the binary created (otherwise it would be a.out)
-lm = links the math library in

And from now on put programming related questions in the programming forum.

All times are GMT -5. The time now is 09:15 PM.