OK folks, if you don’t do any computer programming, then don’t bother reading the rest of this post…you have been warned.
I’ve been working on a program in preparation for an upcomming programming contest I’ll be participating in. In so doing, I’ve been learning a little more about C, as up until now, I’ve been using either C++ or Java (with a little PHP to top it off). I haven’t been completely clueless about C, since if you don’t know at least a little C, you won’t be that good at C++. So, for the past day or so, I’ve been translating a program from C++ to C. This program accepts any number of INTs on stdin, and prints out the prime factors of that int. It seems to work fine in C++, however, I wanted to see if there would be any performance advantage to doing it in C. So, I have it completely translated, and it even compiles…the problem is, however, that it will not link after compilation. I get the following message from ld:
/tmp/ccepGEcX.o: In function `main':
test.c:(.text+0x46): undefined reference to `sqrt'
collect2: ld returned 1 exit status
I even tried to do the following simple test program to make sure it wasn’t something else in my program that was messing up:
#include "stdio.h"
#include "math.h"
int main () {
double test = 5;
double test2 = sqrt(test);
printf("%f", test2);
return 0;
}
By the way, those include lines are using brackets, not quotes, when I try to compile it: stupid HTML. So, my question, to all those C experts, is, WHAT AM I DOING WRONG?!?!
