
gcc - Undefined references
Quote:
>I renamed math.c to arith.c just to avoid a possible confusion suggested
>by someone else with the include file math.h .
No possible confusion here.
Quote:
>Then:
>lroberts:~# gcc -g -o arith.o arith.c -lm
^^^^^^^
As several people pointed out, using the .o "extension" on an executable
file is both confusing and plain stupid.
Quote:
>/tmp/cca001781.o: In function `main':
>/root/arith.c:13: undefined reference to `log'
>/root/arith.c:15: undefined reference to `exp'
>As you see, there isn't any difference in the outcome even with the -lm at
>the end.
It's hard to tell what you're doing wrong or what's wrong with your
installation. Both log and exp work just fine on Linux:
ues12:~/tmp 58> uname -a
Linux ues12 1.2.13 #4 Sat Oct 7 22:32:36 MET 1995 i486
ues12:~/tmp 59> cat test.c
#include <stdio.h>
#include <math.h>
main()
{
printf("%f\n", log(1.0) + exp(0.0));
return 0;
}
ues12:~/tmp 60> gcc test.c -lm
ues12:~/tmp 61> ./a.out
1.000000
My suggestion: go to linux support newsgroup. Your problem has nothing
to do with the topic of this newsgroup: the C programming language.
Quote:
>Thanks for the FAQ suggestion. I'll see if I can find it.
Nobody removed the FAQ from the "standard" places, it's still there.
Dan
--
Dan Pop
CERN, CN Division
Mail: CERN - PPE, Bat. 31 1-014, CH-1211 Geneve 23, Switzerland