I'm porting a piece of C code which uses math functions like floorf(), powf(), expf(), logf(), roundf() etc. I don't see these declared anywhere in our SDK - so how would I best go about compiling the code? Any tips appreciated!
Thu, 2018-02-22 00:06
#1
Missing C math functions (solved)
Just a silly answer:
Did you add/include "math.h"?
#gcc foo.c -o bar -gstabs -Wall
#bar
1.100000 2.200000 1.210000
#
@trixie
Not sure, but if you're using a makefile with seperate compile and link stages, you might also need to add "-lm" to the link stage. I don't know how much precision you need but if you look in math.h there are also double precision versions of most functions.
Newlib should have all those functions. Just make sure that you have "#include <math.h>" in the source file where you want to use them.
@all
The source code did include math.h (that was the first thing I checked) but GCC still complained about an "incompatible implicit declaration of built-in function". I solved the problem by #undef-ining __STRICT_ANSI__ (I didn't realize that the -std=c99 compiler switch in the provided makefile defined this macro automatically).
You should use -std=gnu99 instead of -std=c99 if you don't want __STRICT_ANSI__.
The __STRICT_ANSI__ define makes newlib disable all clib functions that aren't standard ANSI.
@salass00
Good tip, thank you!