This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/57944] New: undefined reference to 'sqrt'


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57944

            Bug ID: 57944
           Summary: undefined reference to 'sqrt'
           Product: gcc
           Version: 4.7.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: spingoogl at shaw dot ca

The following is copy/pasted from my console.
This seems to be simple K&R stuff
The only difference is that in sqrt() I used a variable instead of a number.
The number compiled properly
The variable failed to compile

I tried similar code in cygwin on windows xp using gcc 3.4.4 and it compiled
ok.

Thanks for you time.



gerald@gerald-desktop:~/GTK$ cat pthgrs_good.c
#include <stdio.h>
#include <math.h>
main(){
    double A=3, B=4, C;
    C=sqrt( (double) 25 );
    printf ("The hypotenuse of a triangle with sides of 3 and 4 is %.2f.\n",
C);
    return 0;
}

gerald@gerald-desktop:~/GTK$ gcc pthgrs_good.c -o pthgrs_good.x
gerald@gerald-desktop:~/GTK$ ./pthgrs_good.x 
The hypotenuse of a triangle with sides of 3 and 4 is 5.00.

gerald@gerald-desktop:~/GTK$ cat pthgrs_bad.c
#include <stdio.h>
#include <math.h>
main(){
    double A=3, B=4, C, D=25;
    C=sqrt( (double) D );
    printf ("The hypotenuse of a triangle with sides of 3 and 4 is %.2f.\n",
C);
    return 0;
}

gerald@gerald-desktop:~/GTK$ gcc pthgrs_bad.c -o pthgrs_bad.x
/tmp/cc98lPPJ.o: In function `main':
pthgrs_bad.c:(.text+0x40): undefined reference to `sqrt'
collect2: error: ld returned 1 exit status

gerald@gerald-desktop:~/GTK$ gcc --version
gcc (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]