Skip to main content
CMars.1
Associate
March 6, 2020
Question

Why STM32CubeIDE linker files discard libc.a libg.a and libgcc.a?

  • March 6, 2020
  • 2 replies
  • 1809 views

Just out of curiosity. Why STM32CubeIDE linker files discard libc.a libg.a and libgcc.a?

At the end of the linker file we usually find:

 /* Remove information from the compiler libraries */
 /DISCARD/ :
 {
 libc.a ( * )
 libm.a ( * )
 libgcc.a ( * )
 }

Maybe I didn't get something right but, shouldn't the libc.a include all the C standard library code, so it should be needed to compile a C application?

Regards,

This topic has been closed for replies.

2 replies

BPetk.1
Associate
April 29, 2020

Hi,

Did you by any chance manage to find an answer to this question?

I tried using libc_nano.a instead of libc.a and I wasn't able to compile my code until I changed the linker file to discard libc_nano.a as well.

The linker complained of multiple definitions of almost all functions inside libc.a and I don't know why.

However, in CubeMX there seems to be no option to use libc_nano.a which would generate the correct LD file and this isn't exactly an obvious thing to look for.

Regards

SBrün.1
Visitor II
November 30, 2020

Naming the library in the DISCARD section includes the whole library. You can change it to

libc.a:* ( * )

avoid this.