Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Floating point math (Pow) #39

Open
Kyran-C opened this issue Sep 7, 2018 · 3 comments
Open

Floating point math (Pow) #39

Kyran-C opened this issue Sep 7, 2018 · 3 comments

Comments

@Kyran-C
Copy link

Kyran-C commented Sep 7, 2018

I'm trying to use pow and running into link errors (undefined reference to 'pow'). What flags do I need to change to get floating point math working?

@dvhdr
Copy link
Owner

dvhdr commented Sep 7, 2018

Looks like the fix is to change the order in the linker script, to put libm first:

At this line:
https://github.com/dvhdr/launchpad-pro/blob/master/stm32_flash.ld#L137

change it from:

  /DISCARD/ :
  {
    libc.a ( * )
    libm.a ( * )
    libgcc.a ( * )
  }

to:

  /DISCARD/ :
  {
    libm.a ( * )
    libc.a ( * )
    libgcc.a ( * )
  }

I think this was prematurely instructing the linker to remove references to __errno from libc, which in turn breaks pow.

Referencing pow etc. adds about 13KB to the size of the binary produced, so if you have a large app that might be a problem!

@Kyran-C
Copy link
Author

Kyran-C commented Sep 9, 2018

Tried that, still not working. I was getting the errors initially about __errno, but now it's only saying undefined reference to 'pow'. I did a make clean, reinstalled the VM, overwrote the makefile with the original to make sure there's no changes... Still the same linker error. I've tried putting -lm in the linker flags and few other places and it didn't work. Tried explicitly adding the paths to libm.a and math.h in the makefile LIB and INCLUDES variables. Maybe I'm pointing it at the wrong version, but that didn't help either. Based on the compiler docs, I assume it should be /usr/local/gcc-arm-none-eabi-4_8-2014q3/arm-none-eabi/lib/armv7-m/ I expected it to lookup and link the proper lib since it has the -mcpu=cortex-m3 linker flag, but it seems like the -lm flag isn't working.

@dvhdr
Copy link
Owner

dvhdr commented Sep 11, 2018

Must confess I'm developing locally on my Mac these days, against the v5 ARM tools:
https://launchpad.net/gcc-arm-embedded/5.0/5-2016-q3-update

Are you running on Vagrant, Docker or locally?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants