1 of 1 people found this helpful
In Project -> Build Settings -> ARM -> Linker -> General ->Additional Libraries you need to add "m" to indicate that you want to use mlib library.
Sounds a bit funny, but will work
Keep in mind that power() function is incredibly slow, so in simple case like pow(X, 5), explicit expression X*X*X*X*X will be much faster.
A supererogatory comment of mine ;-)
> Is this intentional to limit code size?
I think that
"z = pow(CONST1, CONST2) ; "
was replaced with
"z = CONST3 ; "
by the compiler,
so you did not need to link the library,
namely libm.a (math library).
All other lines were actually compiled into a function call to "pow()",
so they required link flag to specify appropriate library which contains pow().
In standard C argument specifying a library to link is "-l<x>", which means link "lib<x>.a",
therefore to link with "libm.a" we need to say "-lm",
so we could write "-lm" in the Build Settings ... > ARM .GCC.. > Comipler > Command Line > Custom Flags, too.
About Bob-san's suggestion, in the Linker Additional Libraries, there is a comment
"Additional libraries to link to the executable being created. The linker searches a standard list of directories plus additional specified directories for the specified libraries, which are prepended with "lib" and appended with "a". The linker then uses this file as if it had been specified precisely by name."
This means, for "libm.a" just write "m" ;-)
Thank you all for your help. Adding 'm' to additional libraries did the trick!
You are right about it being incredibly slow! In my application using a PSoc 5 device the operation takes in the region of 75uS!!
Thankfully I only need to perform the calculation occasionally.