Reputation: 314
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.
Upvotes: 0
Views: 1676
Reputation: 1910
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
Upvotes: 3