compiler-errorsruntimelinker-errorsadabuilt-in

How do I implement putchar in C to support RTS?


I'm implementing a minimal Ada RTS for the esp32s3 SoC. Currently, I am stuck with an error that's proving resistant to every solution I've thrown at it. It claims putchar is undefined:

Link
   [link]         blinky.adb
GNU ld (GNU Binutils) 2.42
  Supported emulations:
   elf32xtensa
blinky.o
b__blinky.o
/Users/joe/Development/Ada_Xtensa_ESP32/esp32s3_hal/lib/libEsp32s3_Hal.a
/Users/joe/Development/Ada_Xtensa_ESP32/light_xtensa_esp/adalib/libgnat.a
/Users/joe/.local/share/alire/builds/hal_0.3.1_58bb6bd7/8772a4cbfba2091702a44c6fad50eea0509f0fc415885a6c2d23a26ec134eb8a/lib/libhal.a
/Users/joe/Development/Ada_Xtensa_ESP32/light_xtensa_esp/adalib/libgnat.a
/Users/joe/.local/share/alire/toolchains/gnat_xtensa_esp32_elf_14.2.1_c70145cf/bin/../lib/gcc/xtensa-esp32-elf/14.2.0/../../../../xtensa-esp32-elf/bin/ld: /Users/joe/Development/Ada_Xtensa_ESP32/light_xtensa_esp/adalib/libgnat.a(s-textio.o): in function `system__text_io__put':
s-textio.adb:(.text.system__text_io__put+0x6): undefined reference to `putchar'

However, when I implement putchar, it complains with the error:

   [C]            main.c
/Users/Joe/Development/Ada_Xtensa_ESP32/esp32s3_hal/src/main.c:12:6: error: conflicting types for built-in function 'putchar'; expected 'int(int)' [-Werror=builtin-declaration-mismatch]
   12 | void putchar(int c)

I've tried to undefined putchar and I even added -fno-builtin GCC option and I still get the same error.


Solution

  •    [C]            main.c
    /Users/Joe/Development/Ada_Xtensa_ESP32/esp32s3_hal/src/main.c:12:6: error: conflicting types for built-in function 'putchar'; expected 'int(int)' [-Werror=builtin-declaration-mismatch]
       12 | void putchar(int c)
    

    Over to the right of that message it says

    error: conflicting types for built-in function 'putchar';
       expected 'int(int)'
    

    so I think you should try int putchar(int c).