Sigmund Skjelnes
unread,Aug 12, 2012, 10:15:11 AM8/12/12You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Tried to compile this little program:
/* sqrt-number.c */
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main( int argc, char **argv ){
double f = 9.0;
printf("Kvadratroten av %f er %f\n", f, sqrt(f) );
}
Got this result:
sigmund@sigmund-desktop:~/csrc$ gcc -lm -o sqrt-number sqrt-number.c
/tmp/ccb750CF.o: In function `main':
sqrt-number.c:(.text+0x2f): undefined reference to `sqrt'
collect2: ld returned 1 exit status
Thought maybe libm is missing, it shold be in the package ( for Ubuntu 12.04 ) libc6, and that package is installed.
Tried to find some file which has the name libm.* and got /usr/lib/i386-linux-gnu/libm.so Then I'd tried to set the path to where gcc finds the libraries:
gcc -L/usr/lib/i386-linux-gnu -lm -o sqrt-number sqrt-number.c
again, undefined reference to 'sqrt'
Read somewhere that libraries that neeeded to be linked to the program need only to be listed in the arguments to gcc:
sigmund@sigmund-desktop:~/csrc$ gcc -o sqrt-number /usr/lib/i386-linux-gnu/libm.so sqrt-number.c
/tmp/ccLOlOSu.o: In function `main':
sqrt-number.c:(.text+0x2f): undefined reference to `sqrt'
collect2: ld returned 1 exit status
Obviously gcc cannot find the library, what am I doing wrong here?
Cincerely, Sigmund