PlatformIO Community

How to add -lm option to platformio?

I am using C and i am using the log function and i get errors when compiling so i did a bit of research and found out that you need add -lm option to linker to make it work, so my question is how to add that, i tried reading the docs build options and adding something to platformio.ini file but it didn’t work.

Per build_flags docs, adding linker flags should be done with

build_flags = -Wl,-lm

If that does not appear in the final linker output, resort to scripting, as e.g. seen with add_nanolib.py here and here, just with only "-lm" in the array, or env.Append(LIBS=["m"]).

1 Like