The explanation to what’s happening is very simple:
-
Your
libgplot.adepends onlibm.so, yet the order of-lmand-lgploton the link line is wrong.
The order of libraries on the link line does matter. In general, system libraries (-lpthread,-lm,-lrt,-ldl) should follow everything else on the link line. -
When you remove
-lmfrom the link line,libm.so.6is still pulled into the link by some other library that appears later on the link line (libgd,libxml2orlibcurl) because that library depends onlibm.so.6. But nowlibm.so.6is in correct place on the link line, and so everything works.
if I put -lm at the end of the link command, listing it as the last library, I do not get the error.
That confirms above explanation.