Problems with GCC linker

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Problems with GCC linker

      I needed some new features of the C++ library and so I tried to get NewLib to work. After much effort, I was able to get it to work but I ran into some issues I don't understand.

      I turned off the ES standard library by selecting No for Project Options->Libraries->Include Standard Libraries. I also set Project Options->Libraries->Standard Libraries Directory to None.

      I put the NewLib library files on my machine at: C:/Depot/Source/Library/arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard

      So, I set Project Options->Linker->Additional Linker Options to:
      --verbose -LC:/Depot/Source/Library/arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard

      Here is relevant portion of the output from the linker:

      1> Linking Blinky.elf
      1> "C:/Program Files/SEGGER/EmbeddedStudio/gcc/arm-none-eabi/bin/ld" -X --omagic -eReset_Handler --fatal-warnings --verbose -LC:/Depot/Source/Library/arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard -lc -EL --gc-sections -TC:/Depot/Source/32F401Disc/Blinky/Debug/Blinky.ld -Map Debug/ --defsym=end=__heap_start__ -u_vectors -o Debug/Blinky.elf --emit-relocs --start-group @C:/Depot/Source/32F401Disc/Blinky/Debug/Blinky.ind --end-group
      1> GNU ld (GNU Binutils)
      1> Supported emulations:
      1> armelf
      1> opened script file C:/Depot/Source/32F401Disc/Blinky/Debug/Blinky.ld

      Then a little later:
      1> ==================================================
      1> attempt to open C:/Depot/Source/Library/arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard\libc.a succeeded

      This a little later:
      1> Debug/usbh_cdc.o: In function `USBH_CDC_InterfaceInit':
      1> C:\Depot\Source\32F401Disc\Blinky\Middlewares\ST\STM32_USB_Host_Library\Class\CDC\Src/usbh_cdc.c:170: undefined reference to `malloc'
      1> Debug/usbh_cdc.o: In function `USBH_CDC_InterfaceDeInit':
      1> C:\Depot\Source\32F401Disc\Blinky\Middlewares\ST\STM32_USB_Host_Library\Class\CDC\Src/usbh_cdc.c:296: undefined reference to `free'
      Build failed

      If I add libc.a to the project by adding the line below to the emProject file, I have no link issues.
      <file file_name="../../Library/arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard/libc.a"> />

      Help, please. I cannot work out why the linker won't pick up libc.a when using Project Options->Linker->Additional Linker Options

      PS: I'm happy to post a detailed note on how to get NewLib to work with ES. I wish/beg you to update the library. I think you guys do a fine job overall but this area is seriously lagging.
    • Hello,

      Thank you for your inquiry.
      To make sure we understand you correctly, you want to use newlib. ES gives the error that malloc and free are not defined.
      Adding libc to the mix brings the missing functionality and everything is working correctly?
      This sounds like everything is working as expected to us, or are we missing something in your setup there?

      Best regards,
      Please read the forum rules before posting: Forum Rules

      Keep in mind, this is not a support forum. Its main purpose is user to user interaction.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support contact us per e-mail.
      Alternatively our support ticketing system can be used as well:
    • When I use -L to tell the linker where to look and then -lc to use libc.a, the linker finds libc.a.

      When we use something from libc.a - example, malloc() and free(), they are not found / resolved with libc.a

      If I don't point the linker to libc.a using -L and then -lc but include libc.a as a file in the project, then the linker is able to resolve malloc() and free() to libc.a