Undefined reference to `_exit'

Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/black_f407zg.html
PLATFORM: ST STM32 (15.4.1) > Black STM32F407ZG
HARDWARE: STM32F407ZGT6 168MHz, 128KB RAM, 1MB Flash
DEBUG: Current (blackmagic) External (blackmagic, cmsis-dap, jlink, stlink)     
PACKAGES:
 - toolchain-gccarmnoneeabi @ 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in debug mode
Compiling .pio\build\genericSTM32F407ZGTx\src\Core\Src\gpio.o
Compiling .pio\build\genericSTM32F407ZGTx\src\Core\Src\main.o
Compiling .pio\build\genericSTM32F407ZGTx\src\Core\Src\stm32f4xx_hal_msp.o
Compiling .pio\build\genericSTM32F407ZGTx\src\Core\Src\stm32f4xx_it.o     
Compiling .pio\build\genericSTM32F407ZGTx\src\Core\Src\system_stm32f4xx.o
Compiling .pio\build\genericSTM32F407ZGTx\src\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal.o
Compiling .pio\build\genericSTM32F407ZGTx\src\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_cortex.o
Compiling .pio\build\genericSTM32F407ZGTx\src\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_dma.o   
Compiling .pio\build\genericSTM32F407ZGTx\src\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_dma_ex.o
Compiling .pio\build\genericSTM32F407ZGTx\src\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_exti.o 
Compiling .pio\build\genericSTM32F407ZGTx\src\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash.o
Compiling .pio\build\genericSTM32F407ZGTx\src\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash_ex.o
Compiling .pio\build\genericSTM32F407ZGTx\src\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash_ramfunc.o
Compiling .pio\build\genericSTM32F407ZGTx\src\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_gpio.o
Compiling .pio\build\genericSTM32F407ZGTx\src\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr.o
Compiling .pio\build\genericSTM32F407ZGTx\src\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr_ex.o
Compiling .pio\build\genericSTM32F407ZGTx\src\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc.o
Compiling .pio\build\genericSTM32F407ZGTx\src\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc_ex.o
Compiling .pio\build\genericSTM32F407ZGTx\src\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim.o
Compiling .pio\build\genericSTM32F407ZGTx\src\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim_ex.o
Compiling .pio\build\genericSTM32F407ZGTx\src\startup_stm32f407xx.o
Linking .pio\build\genericSTM32F407ZGTx\firmware.elf
d:/devel/platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m\libc.a(lib_a-exit.o): In function `exit':
exit.c:(.text.exit+0x16): undefined reference to `_exit'  
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\genericSTM32F407ZGTx\firmware.elf] Error 1
=================================================================== [FAILED] Took 1.67 seconds ===================================================================

image

I think it’s missing nano.specs, you only have nosys.specs. Put the pio-gd32f350cb/add_nanolib.py at main · maxgerhardt/pio-gd32f350cb · GitHub in the root of your project and add extra_scripts = add_nanolib.py in the platformio.ini .

1 Like

Thank you, it worked.

I had the same error, in similar STM32 bare metal project. The suggestion from @maxgerhardt solves it, but I’d like to have a bit more understanding of what is going on…
@maxgerhardt , can you briefly explain why this error and why the extra linker flags solve it ?

If you have an empty bare metal project, who/what is calling _exit() ?

Thanks!

1 Like

This happens because PlatformIO also does not know which framework to use.

For boards that only have arduino as availble frameworks, setting that up solves the issue, but then all libs need to be compiled when you build.

Not the best way for sure, but passing by to leave the message that if you add the framework, it works.