Hello there,
I’m writing to discuss an issue with the exported C++ library. I’m integrating the library in an embedded device firmware in C, and as such i followed the “inferencing c example”. While i am able to successfully use the library, there is a workaround i need to use to make it work.
The problem:
To properly feed the classifier i need to verify that i have the correct amount of features by using the defined
#define EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE (EI_CLASSIFIER_RAW_SAMPLE_COUNT * EI_CLASSIFIER_RAW_SAMPLES_PER_FRAME)
this definition is in the model_metadata.h file where there also are 2 variable initializations, for example,
const char* ei_classifier_inferencing_categories[] = { "idle", "snake", "updown", "wave" };
So, when we include this header we risk the multiple definition of … when trying to link it.
It works fine as a shared library because in this case there will be 2 copies of the same data (1 in the library and other in the application).
The workaround:
I compile the library using ar do create an archive of objects, then modify the model_metadata header removing the initialization from the header, and modifying the declarations to external, and that way i can use it in the application.
My suggestion:
Remove this initialization from the header file (although this may require more extensive and complex modifications to the library).
or
Move the macro definitions from this header file to a new one, using an include in model_metadata (so that one can use the the macros without having to include the initialized variables). EDIT: actually this is not a solution because it is included through ei_classifier_types.h which has the result types
I’m trying to use the library as a black box, so that future updates to the classifier can be used without all these steps.
I may be wrong at some point but afaik initializing variables in header files is not recommended practice exactly because of this issue.
Thanks for reading