cancel
Showing results for 
Search instead for 
Did you mean: 

undefined reference to `__fabs'

DLian.3
Associate II

I want to use the intrinsic floating point absolute value function `__fabs` as noted in the compiler specific features in the armcc documentation.

When I build my project using the following settings on STM32CubeIDE:

0693W00000Y8SHHQA3.png 

I get an error saying undefined reference to `__fabs`; when I switch Toolchains to MDK-ARM the project compiles fine with `__fabs`. Are there some settings to enable intrinsic on STM32CubeIDE?

Thanks

5 REPLIES 5
Pavel A.
Evangelist III

> as noted in the compiler specific features in the armcc documentation.

But the compiler of CubeIDE is not armcc. It is gcc.

Wijeden RHIMI
ST Employee

Hello @DLian.3,

I wonder check with you if your issue was resolved or you are stilling blocked :smirking_face: ?

I wait your reply.

Best regards,

Wijeden,

This issue is now resolved.

Wijeden RHIMI
ST Employee

Hello @DLian.3,

Could you please share the solution of your issue !

Best regards,

Wijeden,

DLian.3
Associate II

This may not be the solution you were looking for; however, I was left with some constraints;

  1. I did not want to include the entire math header.
  2. This had to compile for STM32CubeIDE, MDK-ARM, and a linux version.

My goal for the following code snippet was to use the standard math libraries `fabs` function if the intrinsic function was not defined.

// declare math fabs
double fabs(double);
 
// declare instrinsic __fabs for armcc
double __fabs(double value) __attribute__((weak));
double __fabs(double value) {
    // use math libraries if not found
    return fabs(value);
}
 
static inline double floatAbs(double value) {
    return __fabs(value);
}