Using TensorFlowLite library, Mac OS compiling errors for micro_speech_mock

Hi all!

I am trying to get started using the TensorFlowLite library on my Arduino Due!

I have followed TensorFlow’s own instructions to create a library for the Arduino (under the section “Generating Arduino Libraries”:
https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/experimental/micro#generating-arduino_libraries

When I add the .zip library (which I can do seemingly successfully), it also comes with the example micro_speech_mock:

// Template sketch that calls into the detailed TensorFlow Lite example code.

// Include an empty header so that Arduino knows to build the TF Lite library.
#include <TensorFlowLite.h>

extern int tflite_micro_main(int argc, char* argv[]);

void setup() {
  tflite_micro_main(0, NULL);
}

void loop() {
}

When I try to compile the example file, I get the following errors, seemingly from the #include statement on the library (some parts in the middle ommitted for length here):

Arduino: 1.8.9 (Mac OS X), Board: "Arduino Due (Programming Port)"

In file included from /Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/fft.cpp:20:0:
/Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/kiss_fft.h:7:10: warning: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wliteral-suffix]
 #include <string.h>n#include <stdint.h>
          ^
/Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/kiss_fft.h:7:20: warning: extra tokens at end of #include directive [enabled by default]
 #include <string.h>n#include <stdint.h>
                    ^
In file included from /Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/tensorflow/lite/experimental/micro/examples/micro_speech/micro_features/fft_util.cpp:18:0:
/Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/kiss_fft.h:7:10: warning: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wliteral-suffix]
 #include <string.h>n#include <stdint.h>
          ^
/Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/kiss_fft.h:7:20: warning: extra tokens at end of #include directive [enabled by default]
 #include <string.h>n#include <stdint.h>
                    ^
In file included from /Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/_kiss_fft_guts.h:19:0,
                 from /Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/kiss_fft.c:16:
/Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/kiss_fft.h:7:20: warning: extra tokens at end of #include directive [enabled by default]
 #include <string.h>n#include <stdint.h>
                    ^
In file included from /Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/_kiss_fft_guts.h:19:0,
                 from /Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/kiss_fft.c:16:
/Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/kiss_fft.h:58:5: error: unknown type name 'int16_t'
     kiss_fft_scalar r;
     ^
/Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/kiss_fft.h:59:5: error: unknown type name 'int16_t'
     kiss_fft_scalar i;
     ^
/Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/kiss_fft.c: In function 'kf_bfly2':
/Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/kiss_fft.h:48:27: error: 'int16_t' undeclared (first use in this function)
 #  define kiss_fft_scalar int16_t
                           ^
/Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/_kiss_fft_guts.h:65:26: note: in expansion of macro 'kiss_fft_scalar'
 #   define sround( x )  (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
                          ^
/Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/_kiss_fft_guts.h:74:8: note: in expansion of macro 'sround'
  (x) = sround( smul(  x, SAMP_MAX/k ) )
        ^
/Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/_kiss_fft_guts.h:77:10: note: in expansion of macro 'DIVSCALAR'
  do {    DIVSCALAR( (c).r , div);  \
          ^
/Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/kiss_fft.c:33:9: note: in expansion of macro 'C_FIXDIV'
         C_FIXDIV(*Fout,2); C_FIXDIV(*Fout2,2);
         ^
/Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/kiss_fft.h:48:27: note: each undeclared identifier is reported only once for each function it appears in
 #  define kiss_fft_scalar int16_t
                           ^
/Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/_kiss_fft_guts.h:65:26: note: in expansion of macro 'kiss_fft_scalar'
 #   define sround( x )  (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
                          ^
/Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/_kiss_fft_guts.h:74:8: note: in expansion of macro 'sround'
  (x) = sround( smul(  x, SAMP_MAX/k ) )
        ^
/Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/_kiss_fft_guts.h:77:10: note: in expansion of macro 'DIVSCALAR'
  do {    DIVSCALAR( (c).r , div);  \
          ^
/Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/kiss_fft.c:33:9: note: in expansion of macro 'C_FIXDIV'
         C_FIXDIV(*Fout,2); C_FIXDIV(*Fout2,2);
         ^
                
/* edited for length */
             
In file included from /Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/kiss_fft.c:16:0:
/Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/_kiss_fft_guts.h:51:19: error: 'int32_t' undeclared (first use in this function)
 # define SAMPPROD int32_t 
                   ^
/Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/_kiss_fft_guts.h:65:47: note: in definition of macro 'sround'
 #   define sround( x )  (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
                                               ^
/Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/_kiss_fft_guts.h:64:25: note: in expansion of macro 'SAMPPROD'
 #   define smul(a,b) ( (SAMPPROD)(a)*(b) )
                         ^
/Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/_kiss_fft_guts.h:74:16: note: in expansion of macro 'smul'
  (x) = sround( smul(  x, SAMP_MAX/k ) )
                ^
/Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/_kiss_fft_guts.h:77:10: note: in expansion of macro 'DIVSCALAR'
  do {    DIVSCALAR( (c).r , div);  \
          ^
/Users/laurenogden/Documents/Arduino/libraries/micro_speech_mock/src/third_party/kissfft/kiss_fft.c:217:13: note: in expansion of macro 'C_FIXDIV'
             C_FIXDIV(scratch[q1],p);
             ^
exit status 1
Error compiling for board Arduino Due (Programming Port).

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

My friend (on a non Macbook) has taken these same exact steps as me, and he is able to compile and run the example code successfully. I have the most up to date version of the Arduino IDE (1.8.9), and I have xcode and avr-gcc installed. Does anyone have any ideas what might be going wrong and how I can fix this, or has anyone successfully integrated TensorFlowLite with an Arduino before?

Thanks in advance!

  • Lauren

#include <string.h>n#include <stdint.h>

This is due to end of line characters not being correctly interpreted, most likely \n.

One way to fix this is to read the library source code into an editor that can change the line endings.

jremington:
One way to fix this is to read the library source code into an editor that can change the line endings.

Hey! I'm a little confused; what would you suggest changing the line endings to?
Furthermore, the library source code is very extensive; is there a way to resolve this without editing the library code at all, but by changing some settings on my laptop or downloading something new?

Thanks so much!

Sorry, I don't use a Mac. Some info on line endings here.