PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : [C] sqrt in math.h wird nicht gefunden



nul
25-04-2005, 15:47
Es handelt sich um ff. C-Code:

int find_prime( end_of_loop )
int end_of_loop;
{
int is_prime = 1;
int loop_end = (int)sqrt((double)end_of_loop );
int result = -1;
int i = -1;

for ( i = 2; i <= loop_end; i++ )
{
result = end_of_loop % i;
if ( result == 0 )
{
is_prime = 0;
break;
}
}
return is_prime;
}
und folgender Fehlermeldung:

/tmp/cccTcVmx.o(.text+0xfe): In function `find_prime':
/home/xxx/prime.c:45: undefined reference to `sqrt'
collect2: ld returned 1 exit status
Gut, anfangs wuerdet ihr sagen, bindet die math.h ein, das hab ich aber schon laengst gemacht, geht trotzdem nicht :( .
Insgesamt hab ich
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <sys/errno.h>
eingebunden. Befehle wie floor kann ich ausfuehren, das Problem liegt anscheinden nur bei sqrt...
mfg nul

Boron
25-04-2005, 15:53
Du musst dem Linker sagen, dass er die Mathe-Bibliothek zusätzlich zum Linken benutzen soll.

gcc -lm ...

nul
25-04-2005, 15:55
Danke fuer die schnelle Hilfe, manchmal setzt bei mir glaub ich das gehirn aus ;)

Joghurt
28-04-2005, 10:30
Vielleicht interessiert dich auch das:
http://de.wikipedia.org/wiki/Miller-Rabin-Test