Why do you need an explicit `-lm` compiler option? [duplicate]

It is to accomodate systems (mainly embedded) where floating point math is not possible or necessary. It’s kind of historical indeed but don’t forget that gcc and most other C compilers were written in a time where a 386SX was considered a high performance processor.

To give an example, when I still worked in embedded computing, we used standard compilers (Microsoft and Borland) to generate code for our processors (Z80, 80186 and 68030). If the compilers had by default linked to the math library we would have been in trouble as none of our systems had floating point capabilities or even needed them.

It’s true that 30 years afterwards it seems silly but the reason was sound at that time.

Leave a Comment