# Errors with Undefined References (\_exit, \_kill, \_getpid, \_sbrk) in MCUBoot Demo on ESP32

**URL:** <https://forums.freertos.org/t/errors-with-undefined-references-exit-kill-getpid-sbrk-in-mcuboot-demo-on-esp32/22005>\
**Category:** Espressif\
**Tags:** tutorial\
**Created:** [December 4, 2024, 12:18am UTC](https://forums.freertos.org/t/errors-with-undefined-references-exit-kill-getpid-sbrk-in-mcuboot-demo-on-esp32/22005 "2024-12-04T00:18:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adrianomunin](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@adrianomunin](https://forums.freertos.org/u/adrianomunin)\
**Post date:** [December 4, 2024, 12:18am UTC](https://forums.freertos.org/t/errors-with-undefined-references-exit-kill-getpid-sbrk-in-mcuboot-demo-on-esp32/22005/1 "2024-12-04T00:18:39Z")

</div>

Hi all,  
I am following the [FreeRTOS MCUBoot Demo tutorial](https://www.freertos.org/Documentation/03-Libraries/05-FreeRTOS-labs/05-FreeRTOS-MCUBoot/mcuboot-demo) which demonstrates how to build and use MCUBoot on an ESP32 with FreeRTOS. This is based on the [this GitHub Project.](https://github.com/FreeRTOS/Lab-Project-FreeRTOS-MCUBoot), However, when I run the command:

```auto
cmake --build build --target mcuboot-flash
```

I encounter the following error related to undefined references:

```auto
undefined reference to '_exit', '_kill', '_getpid', and '_sbrk'
```

Below is the full output of the error:

```auto
admunin@PC:~/Documents/Lab-Project-FreeRTOS-MCUBoot/proj/espressif/esp32/bootloader$ cmake --build build --target mcuboot-flash
[1/3] Linking C executable mcuboot_esp32.elf
FAILED: mcuboot_esp32.elf 
: && /home/admunin/.espressif/tools/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin/xtensa-esp32-elf-gcc -mlongcalls -Wno-frame-address -Wl,--gc-sections CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/freertos/main.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/freertos/keys.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/bootutil/src/boot_record.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/bootutil/src/bootutil_misc.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/bootutil/src/bootutil_public.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/bootutil/src/caps.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/bootutil/src/encrypted.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/bootutil/src/fault_injection_hardening.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/bootutil/src/fault_injection_hardening_delay_rng_mbedtls.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/bootutil/src/image_ec.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/bootutil/src/image_ec256.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/bootutil/src/image_ed25519.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/bootutil/src/image_rsa.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/bootutil/src/image_validate.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/bootutil/src/loader.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/bootutil/src/swap_misc.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/bootutil/src/swap_move.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/bootutil/src/swap_scratch.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/bootutil/src/tlv.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/boot_serial/src/boot_serial.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/boot_serial/src/cbor_common.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/boot_serial/src/cbor_decode.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/boot_serial/src/cbor_encode.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/boot_serial/src/serial_recovery_cbor.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/ext/mbedtls/library/sha256.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/ext/mbedtls/library/platform_util.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/ext/mbedtls/library/asn1parse.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/ext/mbedtls/library/ecp.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/ext/mbedtls/library/ecp_curves.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/ext/mbedtls/library/bignum.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/ext/mbedtls/library/ecdsa.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/ext/mbedtls/library/base64.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/ext/mbedtls/library/memory_buffer_alloc.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/ext/tinycrypt/lib/source/ecc.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/ext/tinycrypt/lib/source/ecc_dsa.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/ext/tinycrypt/lib/source/sha256.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/ext/tinycrypt/lib/source/utils.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/espressif/port/esp_mcuboot.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/espressif/port/esp_loader.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/port/espressif/src/boot_startup_port.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/port/espressif/src/boot_log_port.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/port/espressif/src/boot_assert_port.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/port/espressif/src/boot_wdt_port.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/port/espressif/src/boot_heap_port.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/port/espressif/src/boot_serial_port.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/port/espressif/src/system_port.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/port/espressif/src/base64_port.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/port/espressif/src/crc16_port.c.obj CMakeFiles/mcuboot_esp32.elf.dir/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/lib/mcuboot/boot/espressif/hal/esp-idf/components/soc/esp32/uart_periph.c.obj -o mcuboot_esp32.elf -T/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/proj/espressif/esp32/bootloader/ld/bootloader.ld -T/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/proj/espressif/esp32/bootloader/ld/rom_32.ld -nostdlib -mlongcalls -Wno-frame-address -Wl,--cref -Wl,--Map=mcuboot_esp32.map -fno-rtti -fno-lto -Wl,--gc-sections -Wl,--undefined=uxTopUsedPriority -lm -lgcc -lgcov -lstdc++ -lc boot/espressif/hal/libhal.a -Wno-frame-address -Wl,--cref -Wl,--Map=mcuboot_esp32.map -fno-rtti -fno-lto -Wl,--gc-sections -Wl,--undefined=uxTopUsedPriority -lm -lgcc -lgcov -T/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/proj/espressif/esp32/bootloader/../../../../lib/mcuboot/boot/espressif/hal/esp-idf/components/esp_rom/esp32/ld/esp32.rom.ld -T/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/proj/espressif/esp32/bootloader/../../../../lib/mcuboot/boot/espressif/hal/esp-idf/components/esp_rom/esp32/ld/esp32.rom.libgcc.ld -T/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/proj/espressif/esp32/bootloader/../../../../lib/mcuboot/boot/espressif/hal/esp-idf/components/esp_rom/esp32/ld/esp32.rom.api.ld -T/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/proj/espressif/esp32/bootloader/../../../../lib/mcuboot/boot/espressif/hal/esp-idf/components/esp32/ld/esp32.peripherals.ld -T/home/admunin/Documents/Lab-Project-FreeRTOS-MCUBoot/proj/espressif/esp32/bootloader/../../../../lib/mcuboot/boot/espressif/hal/esp-idf/components/esp_rom/esp32/ld/esp32.rom.newlib-funcs.ld && :
/home/admunin/.espressif/tools/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld: mcuboot_esp32.elf section `.iram.text' will not fit in region `iram_seg'
/home/admunin/.espressif/tools/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld: region `iram_seg' overflowed by 176 bytes
/home/admunin/.espressif/tools/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld: /home/admunin/.espressif/tools/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/lib/esp32/no-rtti/libc.a(libc_a-abort.o):(.literal+0x0): undefined reference to `_exit'
/home/admunin/.espressif/tools/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld: /home/admunin/.espressif/tools/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/lib/esp32/no-rtti/libc.a(libc_a-abort.o): in function `abort':
/builds/idf/crosstool-NG/.build/xtensa-esp-elf/src/newlib/newlib/libc/stdlib/abort.c:58:(.text+0xa): undefined reference to `_exit'
/home/admunin/.espressif/tools/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld: /home/admunin/.espressif/tools/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/lib/esp32/no-rtti/libc.a(libc_a-signalr.o):(.literal+0x4): undefined reference to `_kill'
/home/admunin/.espressif/tools/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld: /home/admunin/.espressif/tools/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/lib/esp32/no-rtti/libc.a(libc_a-signalr.o):(.literal+0x8): undefined reference to `_getpid'
/home/admunin/.espressif/tools/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld: /home/admunin/.espressif/tools/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/lib/esp32/no-rtti/libc.a(libc_a-signalr.o): in function `_kill_r':
/builds/idf/crosstool-NG/.build/xtensa-esp-elf/src/newlib/newlib/libc/reent/signalr.c:53:(.text+0xe): undefined reference to `_kill'
/home/admunin/.espressif/tools/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld: /home/admunin/.espressif/tools/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/lib/esp32/no-rtti/libc.a(libc_a-signalr.o): in function `_getpid_r':
/builds/idf/crosstool-NG/.build/xtensa-esp-elf/src/newlib/newlib/libc/reent/signalr.c:83:(.text+0x27): undefined reference to `_getpid'
/home/admunin/.espressif/tools/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld: /home/admunin/.espressif/tools/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/lib/esp32/no-rtti/libc.a(libc_a-sbrkr.o):(.literal+0x0): undefined reference to `_sbrk'
/home/admunin/.espressif/tools/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld: /home/admunin/.espressif/tools/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/lib/esp32/no-rtti/libc.a(libc_a-sbrkr.o): in function `_sbrk_r':
/builds/idf/crosstool-NG/.build/xtensa-esp-elf/src/newlib/newlib/libc/reent/sbrkr.c:51:(.text+0xc): undefined reference to `_sbrk'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
```

Has anyone encountered this issue before? Any advice on how to resolve the undefined references to \_exit, \_kill, \_getpid, and \_sbrk?

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [December 4, 2024, 9:47am UTC](https://forums.freertos.org/t/errors-with-undefined-references-exit-kill-getpid-sbrk-in-mcuboot-demo-on-esp32/22005/2 "2024-12-04T09:47:40Z")

</div>

Can you try providing empty definitions of these functions -

```auto
void* _sbrk_r(struct _reent *r, ptrdiff_t sz)
{

}
int _getpid_r(struct _reent *r)
{

}
int _kill_r(struct _reent *r, int pid, int sig)
{

}
void _exit(int __status)
{

}

```

The latest ESP-IDF contains these definitions - [esp-idf/components/newlib/syscalls.c at 030c9957dbc5c5a627cf1bb4b2b856f1b6c1343c · espressif/esp-idf · GitHub](https://github.com/espressif/esp-idf/blob/030c9957dbc5c5a627cf1bb4b2b856f1b6c1343c/components/newlib/syscalls.c#L144-L151).
