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

  • From:
  • To:
  • Subject: Re: unidentified reference to 'sqrt' why is this so ?
  • Date: Wed, 2 Jan 2013 10:17:18 +0100 (CET)


----- Original Message -----
> 
> 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.
> > 
> > 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.
> 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

This is indeed an error from ld, the link editor.

> 
> 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;
> 
...
>        x2 = ( -b - sqrt(delta) )/( 2.0*a );
...
> [/code]
> 
> this float work on g++ above, but, i said , not work on gcc   !

g++ links with libstdc++ and perhaps also libm. With gcc, you need to link 
with libm.

Note also that if you are using C99, then you can use sqrtf (float version of 
sqrt which takes/returns doubles). You might get better performance with 
that, at the cost of limiting portability (esp. to Windows).

A+
Paul




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