undefined reference to ...
Hey, I am new to both these forums and C in general, so I might be overlooking something simple. If that's the case, sorry, but Google searches got me nothing. Here's the problem:
I am going to Project Euler's problems, and am hitting a wall with both Project 7 and Project 3. Both of those involve deciding whether a number is a prime, which I have implemented with an additional function that looks like this:
Code:
/* Prime Number Checker
* Takes an integer as an argument
* Returns 1 if the integer is prime
* Returns 0 if the integer is composite
*/
int is_prime(int n)
{
int i;
for (i = 2; i < sqrt(n); i++)
{
if ( n%i == 0 && n > 3)
{
return 0;
}
}
return 1;
}
There may be a more efficient way to implement this, but I think this should work. I have #included <math.h> as well. Here is how the rest of my ideas fit into this:
I have a 003.c (007.c too, but that's irrelevant for now) file in my .../003 folder, as well as a soft link functions.h to .../Functions/functions.h, where my is_prime function is. I've included <math.h> and "functions.h in the 003.c. Somehow functions.h compiles with no problems, but 003.c gives me the
Code:
undefined reference to 'sqrt'
There is a little more text to the warning, but I don't see how it could be helpful or relevant. I'll paste it if needed.
Any thoughts?