Where is math.h?

valery
Posts: 5
Joined: Sun May 03, 2020 12:20 pm

Where is math.h?

Postby valery » Sun May 03, 2020 12:25 pm

Hi, I try to use sqrt() and atan() functions. Where they are in IDF library? Which header file declares them?

Angus
Espressif staff
Espressif staff
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Where is math.h?

Postby Angus » Mon May 04, 2020 12:02 am

Hi valery,

math.h is installed as part of the libc (newlib), so on recent ESP-IDF versions it's installed alongside the toolchain (gcc) not inside ESP-IDF itself. If you look around the location where the toolchain is installed then you can find it (note that recent versions of ESP-IDF ship a few different newlib variants with different compile options so there may be multiple toolchain subdirectories with different newlibs).

However, you may not need to find this header. All the libc standard functions in math.h should be present and the header should include cleanly, and the functions should compile and link correctly.

If you're having a specific problem getting something to work, please post some more details and the error message and we'll try to help.

valery
Posts: 5
Joined: Sun May 03, 2020 12:20 pm

Re: Where is math.h?

Postby valery » Wed May 13, 2020 5:42 pm

Thank you. Is there a way to find location of a header file without IDE? Some time just want to look inside a header file, and wondering if IDF has some analog to 'whereis' tool.

SamoESP
Posts: 1
Joined: Mon Oct 02, 2023 11:27 am

Re: Where is math.h?

Postby SamoESP » Mon Oct 02, 2023 11:34 am

I have a similar problem. When I add math.h I get warning "The math library must be enabled by CONFIG_NEWLIB_LIBC to be included in the build. Due to this fact, I added sdkconfig.defaults file where I added CONFIG_NEWLIB_LIBC=y and instead of <math.h> I include <newlib.h>. I try to use math functions but are not visible. Please let me know what I have to do?

adokitkat
Espressif staff
Espressif staff
Posts: 77
Joined: Thu Jun 22, 2023 12:50 pm

Re: Where is math.h?

Postby adokitkat » Fri Oct 06, 2023 1:09 pm

Hi SamoESP, what do you use Arduino or ESP-IDF? Also what version? I cannot reproduce your problem. ESP32 ROM and ESP-IDF use Newlib instead of glibc as their standard C library, it is always included. You should be able to just do `#include <math.h>`.

geonimo22
Posts: 4
Joined: Thu May 22, 2025 12:24 pm

Re: Where is math.h?

Postby geonimo22 » Fri Aug 08, 2025 12:45 pm

Hello,
despite post has 2 years, I faced same issue. in the ULP co-processor, I manage to use some math function with a constant but not with a variable "sqrt(4) is ok but sqrt(myvariable) is creating compilation error : undefined reference to `sqrt'.
This works perfectly on main program, just not when it is in ULP co-processor.
I use PIO with ESP-IDF 5.4.1.
I tried to add this CONFIG_NEWLIB_LIBC, but not working neither.
Any idea how to solve ?

Who is online

Users browsing this forum: Barkrowler, Bing [Bot] and 6 guests