unidentified reference to 'sqrt' why is this so ?

  • From: "wolfram" < >
  • To:
  • Subject: unidentified reference to 'sqrt' why is this so ?
  • Date: Tue, 01 Jan 2013 09:44:03 -0500


Paul Floyd wrote:
> wolfram wrote:
> 
> 
> > 
> > Hi, i try to compile this float on .C Netbeans, and i use ubuntu 12.04, 
> > but not work it. it occurs an error, unidentified reference to 'sqrt ! 
> > meanwhile, i loaded libm.so , but didnt change anything.
> > 
> 
> Hi
> 
> Can you copy and paste the exact error? I still can't tell for sure 
> whether it is a compiler error (unlikely) or a linker error.
> 
> On Solaris, as an example, this code
> 
> #include <math.h>
> 
> int main()
> {
> sqrt(25.0);
> return 0;
> }
> 
> Gives this error
> 
> cc -o s s.c
> Undefined                       first referenced
> symbol                             in file
> sqrt                                s.o
> 
> Paul


[code]

******give an error as this*****

"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/wolfram/NetBeansProjects/CppApplication_1'
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk 
dist/Debug/GNU-Linux-x86/cppapplication_1
make[2]: Entering directory `/home/wolfram/NetBeansProjects/CppApplication_1'
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/newfile24.o.d
gcc     -c -g -MMD -MP -MF build/Debug/GNU-Linux-x86/newfile24.o.d -o 
build/Debug/GNU-Linux-x86/newfile24.o newfile24.c
mkdir -p dist/Debug/GNU-Linux-x86
gcc      -o dist/Debug/GNU-Linux-x86/cppapplication_1 
build/Debug/GNU-Linux-x86/newfile24.o  
build/Debug/GNU-Linux-x86/newfile24.o: In function `main':
/home/wolfram/NetBeansProjects/CppApplication_1/newfile24.c:14: undefined 
reference to `sqrt'
/home/wolfram/NetBeansProjects/CppApplication_1/newfile24.c:15: undefined 
reference to `sqrt'
/home/wolfram/NetBeansProjects/CppApplication_1/newfile24.c:22: undefined 
reference to `sqrt'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/cppapplication_1] Error 1
make[2]: Leaving directory `/home/wolfram/NetBeansProjects/CppApplication_1'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/wolfram/NetBeansProjects/CppApplication_1'
make: *** [.build-impl] Error 2


BUILD FAILED (exit value 2, total time: 1s)
[code]

upon to compile this float
[code]
#include <stdio.h>
#include <math.h>

int main()
{
    float a, b, c, delta, x1, x2, x, kok_delta;

    printf("a, b, c degerlerini girin:\n");
    scanf("%f %f %f",&a,&b,&c);

    delta = b*b - 4.0*a*c;

    if( delta > 0.0 ){
       x1 = ( -b + sqrt(delta) )/( 2.0*a );
       x2 = ( -b - sqrt(delta) )/( 2.0*a );

       printf("\nReel kokler:");
       printf("\nx1 = %f",x1);
       printf("\nx2 = %f",x2);
    } 
    else if( delta < 0.0 ){
       kok_delta = ( sqrt(-delta) ) / (2.0*a);
       x = -0.5*b/a;

       printf("\nKarmasik kokler:");
       printf("\nx1 = %f + (%f)i", x, kok_delta);
       printf("\nx2 = %f - (%f)i", x, kok_delta);
    }
    else{
       x = -0.5*b/a;

       printf("\nKokler eşit:");
       printf("\nx1 = x2 = %f",x);
    }

  return 0;
}
[/code]

this float work on g++ above, but, i said , not work on gcc   !






unidentified reference to 'sqrt' why is this so ?

wolfram 01/01/2013

Re: unidentified reference to 'sqrt' why is this so ?

paulf 01/02/2013

<Possible follow-up(s)>

unidentified reference to 'sqrt' why is this so ?

soldatov 01/02/2013

Project Features

About this Project

CND was started in November 2009, is owned by Leonid Lenyashin, and has 130 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close