#include <cstdarg> error

I’m trying to use TensorFlow Lite for Microcontrollers, but I’m having issues with compiling the sketch (I’m just running the Hello World example for now). I’ve been trying to search for the issue with cstdarg, but haven’t had any luck - anything I’ve found has related to the .h files of custom libraries, but cstdarg isn’t a custom library.

For reference, the requirements listed for TensorFlow Lite for Microcontrollers are:

  • C/C++ compiler capable of C++11 compatibility
  • Debug logging
  • The C standard libm.a library
    [liGlobal variable initialization[/li]
    [/list]

And the error output is:

Arduino: 1.8.10 (Linux), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

/home/user2/Downloads/arduino-1.8.10-linux64/arduino-1.8.10/arduino-builder -dump-prefs -logger=machine -hardware /home/user2/Downloads/arduino-1.8.10-linux64/arduino-1.8.10/hardware -hardware /home/user2/.arduino15/packages -tools /home/user2/Downloads/arduino-1.8.10-linux64/arduino-1.8.10/tools-builder -tools /home/user2/Downloads/arduino-1.8.10-linux64/arduino-1.8.10/hardware/tools/avr -tools /home/user2/.arduino15/packages -built-in-libraries /home/user2/Downloads/arduino-1.8.10-linux64/arduino-1.8.10/libraries -libraries /home/user2/Arduino/libraries -fqbn=arduino:avr:mega:cpu=atmega2560 -ide-version=10810 -build-path /tmp/arduino_build_819574 -warnings=none -build-cache /tmp/arduino_cache_13495 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=/home/user2/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=/home/user2/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.avr-gcc.path=/home/user2/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino5.path=/home/user2/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5 -prefs=runtime.tools.avrdude.path=/home/user2/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=/home/user2/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -verbose /home/user2/Arduino/libraries/Arduino_TensorFlowLite/examples/hello_world/hello_world.ino
/home/user2/Downloads/arduino-1.8.10-linux64/arduino-1.8.10/arduino-builder -compile -logger=machine -hardware /home/user2/Downloads/arduino-1.8.10-linux64/arduino-1.8.10/hardware -hardware /home/user2/.arduino15/packages -tools /home/user2/Downloads/arduino-1.8.10-linux64/arduino-1.8.10/tools-builder -tools /home/user2/Downloads/arduino-1.8.10-linux64/arduino-1.8.10/hardware/tools/avr -tools /home/user2/.arduino15/packages -built-in-libraries /home/user2/Downloads/arduino-1.8.10-linux64/arduino-1.8.10/libraries -libraries /home/user2/Arduino/libraries -fqbn=arduino:avr:mega:cpu=atmega2560 -ide-version=10810 -build-path /tmp/arduino_build_819574 -warnings=none -build-cache /tmp/arduino_cache_13495 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=/home/user2/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=/home/user2/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.avr-gcc.path=/home/user2/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino5.path=/home/user2/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5 -prefs=runtime.tools.avrdude.path=/home/user2/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=/home/user2/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -verbose /home/user2/Arduino/libraries/Arduino_TensorFlowLite/examples/hello_world/hello_world.ino
Using board 'mega' from platform in folder: /home/user2/.arduino15/packages/arduino/hardware/avr/1.8.2
Using core 'arduino' from platform in folder: /home/user2/.arduino15/packages/arduino/hardware/avr/1.8.2
Detecting libraries used...
/home/user2/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10810 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -I/home/user2/.arduino15/packages/arduino/hardware/avr/1.8.2/cores/arduino -I/home/user2/.arduino15/packages/arduino/hardware/avr/1.8.2/variants/mega /tmp/arduino_build_819574/sketch/hello_world.ino.cpp -o /dev/null
Alternatives for TensorFlowLite.h: [Arduino_TensorFlowLite@1.15.0-ALPHA]
ResolveLibrary(TensorFlowLite.h)
  -> candidates: [Arduino_TensorFlowLite@1.15.0-ALPHA]
/home/user2/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10810 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -I/home/user2/.arduino15/packages/arduino/hardware/avr/1.8.2/cores/arduino -I/home/user2/.arduino15/packages/arduino/hardware/avr/1.8.2/variants/mega -I/home/user2/Arduino/libraries/Arduino_TensorFlowLite/src /tmp/arduino_build_819574/sketch/hello_world.ino.cpp -o /dev/null
Alternatives for cstdarg: []
ResolveLibrary(cstdarg)In file included from /home/user2/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/micro_error_reporter.h:18:0,
                 from /tmp/arduino_build_819574/sketch/output_handler.h:20,

  -> candidates: []
Multiple libraries were found for "TensorFlowLite.h"
                 from /home/user2/Arduino/libraries/Arduino_TensorFlowLite/examples/hello_world/hello_world.ino:21:
 Used: /home/user2/Arduino/libraries/Arduino_TensorFlowLite
/home/user2/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/core/api/error_reporter.h:18:10: fatal error: cstdarg: No such file or directory
 #include <cstdarg>
          ^~~~~~~~~
compilation terminated.
Using library Arduino_TensorFlowLite at version 1.15.0-ALPHA in folder: /home/user2/Arduino/libraries/Arduino_TensorFlowLite 
exit status 1
Error compiling for board Arduino Mega or Mega 2560.

I’m getting the error even when I strip down the code to

#include <TensorFlowLite.h>
#include "tensorflow/lite/experimental/micro/micro_error_reporter.h"

void setup() {  
}


void loop() { 
}

so it’s definitely being triggered by the include statements.

Does anyone have any idea why the sketch can’t be compiled, and if so, how to resolve the issue?

shouldn’t an include file have a “.h” suffix?

gcjr:
shouldn’t an include file have a “.h” suffix?

Only if it’s a C header. C++ standard library headers don’t have suffixes.

The AVR compiler used by Arduino doesn’t include the C++ standard library.

Try installing ArduinoSTL, and #include <ArduinoSTL.h> at the top of your sketch (you might have to include it in the Tensorflow implementation files as well).

Pieter

The AVR does have a #include <stdarg.h> which is a C file and not C++.

You will quickly find that these AI libraries are extremely memory hog. Also, 8 bits microcontroller is extremely slow for you to be able to do anything meaningful.

Just try different boards and not Arduino.

I took a look at the tensor flow lit e site and it says it requires a 32 bit processor to run. So the Mega board is not compatible with it.