Skip to main content
DLian.3
Associate II
Jan 17, 2023 5:55 PM UTC
Question

undefined reference to `__fabs'

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

This topic has been closed for replies.

5 replies

Pavel A.
Jan 17, 2023 6:06 PM UTC

> 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
Jan 19, 2023 3:43 PM UTC

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,

DLian.3
DLian.3Author
Associate II
Jan 19, 2023 5:00 PM UTC

This issue is now resolved.

Wijeden RHIMI
ST Employee
Jan 20, 2023 8:47 AM UTC

Hello @DLian.3,

Could you please share the solution of your issue !

Best regards,

Wijeden,

DLian.3
DLian.3Author
Associate II
Jan 23, 2023 5:06 PM UTC

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);
}