0

when I am tring to compile

#include <math.h>
#include <stdio.h>
int main()
{
   double m=1.66666;
   double k=sqrtf(m);
   return 0;
}

using following command

/user/unicore/rs6000aix/compiler/gcc4.8.5/aix6.1/bin/gcc -o test.out test.cpp -lm

it throws

ld: 0711-317 ERROR: Undefined symbol: .sqrtf

ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information. collect2: error: ld returned 8 exit status

But below code compiles successfully

#include <math.h>
#include <stdio.h>
int main()
{
   double k=sqrtf(1.66666);
   return 0;
}

I am using gcc4.8.5 to compile the code ..same code compiles successfully on AIX6.1 but it is failing on new machine(AIX7.1)

Similar question already exist on this: Why am I getting "undefined reference to sqrt" error even though I include math.h header? but it is not working for me.

Update: when I use sqrt instead of sqrtf code compiles successfully, using command '/user/unicore/rs6000aix/compiler/gcc4.8.5/aix6.1/bin/gcc -o test.out test.cpp -lm to compile it.sqrtf` fails with or without linking to math library.

edit2: output of nm command

$ nm -g -X32 /usr/lib/libm.a | grep sqrtf
.csqrtf              T         512
csqrtf               D        4196          12

$ nm -g -X64 /usr/lib/libm.a | grep sqrtf
.csqrtf              T         512
csqrtf               D        4296          24

edit 3: bos.adt.libm.7.1.3.47 was installed which doesn't have sqrtf. Installed bos.adt.libm.7.1.4.30.bff and it started to work fine.

BitMask
  • 314
  • 2
  • 9

1 Answers1

3

Install package bos.adt.libm. Or ask you system-administrator to do so.

--

Edit: The call of function sqrtf in your code might very well be optimized away, as it can be calculated compile-time, also the result is never used. Here is an actual example:

#include <math.h>
#include <stdio.h>
int main (int argc,char **argv)
{
    double val, k;

    if (argc>1) val= strtod (argv[1], NULL);
    else        val= 1.66666;

    k=sqrtf (val);
    printf ("val=%g k=%g\n", val, k);

    return 0;
}

Compilation:

gcc -o sid_math sid_math.c -Wl,-bmap:sid_math.map # fails
gcc -o sid_math sid_math.c -lm -Wl,-bmap:sid_math.map # works

-- Edit: also you should examine the content of libma.a, eg:

$ nm -g -X32 /usr/lib/libm.a | grep sqrtf
.csqrtf              T         512
csqrtf               D        4132          12
.sqrtf               T         480
sqrtf                D        6364          12

$ nm -g -X64 /usr/lib/libm.a | grep sqrtf
.csqrtf              T         512
csqrtf               D        4232          24
.sqrtf               T         480
sqrtf                D        6616          24
Lorinczy Zsigmond
  • 1,749
  • 1
  • 14
  • 21
  • `bos.adt.libm` package is already Installed. when I run following command `lslpp -l | grep bos.adt.libm `. I get ` bos.adt.libm 7.1.4.0 COMMITTED Base Application Development`. I can see **usr/lib/libm.a** present on my system. – BitMask Dec 03 '18 at 08:41
  • one update: when I use `sqrt` instead of `sqrtf` code compiles successfully. when I use the command '/user/unicore/rs6000aix/compiler/gcc4.8.5/aix6.1/bin/gcc -o test.out test.cpp -lm` to compile it. `sqrtf` fails with or without linking to math library. – BitMask Dec 03 '18 at 09:57
  • 1
    Report the bug to your AIX-vendor. – Lorinczy Zsigmond Dec 03 '18 at 12:15
  • 1
    Thank you!! Installing latest `bos.adt.libm` solved the problem. – BitMask Dec 05 '18 at 09:57