tensorflow / tflite-micro

Infrastructure to enable deployment of ML models to low-power resource-constrained embedded targets (including microcontrollers and digital signal processors).
Apache License 2.0
1.85k stars 805 forks source link

error: redefinition of 'struct kiss_fft_float::kiss_fft_state' #2530

Closed hiccuplp closed 6 months ago

hiccuplp commented 6 months ago

I'm studying the textbook, following the tutorial step by step, and I have this problem. I ask for help. Thank you!

Linux git clone git@github.com:tensorflow/tflite-micro.git tflite_micro_lite

make -f tensorflow/lite/micro/tools/make/Makefile test_hello_world_test

error log : ... g++ -std=c++11 -fno-rtti -fno-exceptions -fno-threadsafe-statics -Wnon-virtual-dtor -Werror -fno-unwind-tables -ffunction-sections -fdata-sections -fmessage-length=0 -DTF_LITE_STATIC_MEMORY -DTF_LITE_DISABLE_X86_NEON -Wsign-compare -Wdouble-promotion -Wunused-variable -Wunused-function -Wswitch -Wvla -Wall -Wextra -Wmissing-field-initializers -Wstrict-aliasing -Wno-unused-parameter -DKERNELS_OPTIMIZED_FOR_SPEED -DTF_LITE_USE_CTIME -O2 -I. -Itensorflow/lite/micro/tools/make/downloads -Itensorflow/lite/micro/tools/make/downloads/gemmlowp -Itensorflow/lite/micro/tools/make/downloads/flatbuffers/include -Itensorflow/lite/micro/tools/make/downloads/kissfft -Itensorflow/lite/micro/tools/make/downloads/ruy -Igen/linux_x86_64_default_gcc/genfiles/ -Igen/linux_x86_64_default_gcc/genfiles/ -c signal/src/kiss_fft_wrappers/kiss_fft_float.cc -o gen/linux_x86_64_default_gcc/obj/kernels/signal/src/kiss_fft_wrappers/kiss_fft_float.o

In file included from tensorflow/lite/micro/tools/make/downloads/kissfft/tools/kiss_fftr.c:16:0, from signal/src/kiss_fft_wrappers/kiss_fft_float.cc:21: tensorflow/lite/micro/tools/make/downloads/kissfft/_kiss_fft_guts.h:28:8: error: redefinition of 'struct kiss_fft_float::kiss_fft_state' struct kiss_fft_state{ ^~~~~~ In file included from tensorflow/lite/micro/tools/make/downloads/kissfft/kiss_fft.c:16:0, from signal/src/kiss_fft_wrappers/kiss_fft_float.cc:20: tensorflow/lite/micro/tools/make/downloads/kissfft/_kiss_fft_guts.h:28:8: note: previous definition of 'struct kiss_fft_float::kiss_fft_state' struct kiss_fft_state{ ^~~~~~ tensorflow/lite/micro/tools/make/Makefile:830: recipe for target 'gen/linux_x86_64_default_gcc/obj/kernels/signal/src/kiss_fft_wrappers/kiss_fft_float.o' failed make: *** [gen/linux_x86_64_default_gcc/obj/kernels/signal/src/kiss_fft_wrappers/kiss_fft_float.o] Error 1

hiccuplp commented 6 months ago

This problem is easy to solve. Generally, the target header file .h does not contain conditional compilation statements. The statement format is fixed.

ifndef _TESTH

define _TESTH

..

endif

Add the preceding code to the beginning and end of the header file .h to avoid repeated definition.

include "xxx.h" actually expands the .h file content before the .c file. If the xxx.h file is not compiled with conditions, multiple repeated definitions will be expanded before the .c code during repeated reference and cyclic recursion include. In this case, alarms are repeatedly defined during compilation.