Very strange linker behavior

The explanation to what’s happening is very simple:

  1. Your libgplot.a depends on, yet the order of -lm and -lgplot on 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.

  2. When you remove -lm from the link line, is still pulled into the link by some other library that appears later on the link line (libgd, libxml2 or libcurl) because that library depends on But now is 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.

Leave a Comment