KKyang
KKyang

Reputation: 45

ld: "undefined reference to symbol 'sqrtf'" error with G++ via Apache Ant

Recently, I'm trying to use Apache Ant with g++4.8 with -std=c++11.

If I tried this code it passed.

#include <cmath>
...
sqrtf((float)100);

However, if I type:

#include <cmath>
...
sqrt((float)100);

The g++ compiler will produce the error:

/usr/bin/ld: test.o: undefined reference to symbol 'sqrtf@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

Adding -lm doesn't help either. Any ideas?

Thanks!

Upvotes: 0

Views: 1145

Answers (2)

Beto
Beto

Reputation: 11

The problem is not apache ant, in some Linux distributions the g++ and gcc compilers require "-lm" to link the cmath lib that is included by "math.h" in C and "cmath" in C++

Upvotes: 1

KKyang
KKyang

Reputation: 45

I found the solution. It seems that Apache Ant is a bit different from the command line using g++ which needs to add the -lm function with a linking argument as follows.

<linkerarg location="end" value="-lm">

Since I'm not familiar with Ant, the first time I wrote the argument with no location and Apache Ant gave me an error. :(

Upvotes: 0

Related Questions