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.8k stars 789 forks source link

Error while porting to MT6261 (creating static library) #1163

Closed Nafihahmd closed 1 year ago

Nafihahmd commented 2 years ago

I am following the Porting to a new platform guide. I created directory tree containing only the sources that are necessary to build a static library. The issue started when I tried to compile it with the armcc compiler. My makefile is as follows:

CC:= armcc
CPPFLAGS:= --thumb --cpp
BUILD_DIR:= ./build
SRC_DIRS:= 

SRCS:= $(shell find $(SRC_DIRS) -name "*.cc")
OBJS:= $(SRCS:%=$(BUILD_DIR)/%.o)

# String substitution (suffix version without %).
# As an example, ./build/hello.cpp.o turns into ./build/hello.cpp.d
DEPS := $(OBJS:.o=.d)

INC_DIRS:= $(shell find $(SRC_DIRS) -type "d")
INC_FLAGS:= $(addprefix -I,$(INC_DIRS))

CPPFLAGS := $(INC_FLAGS)

# The final build step.
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
    @echo "SRC_Files = $(SRCS)"
    ar rcs $(BUILD_DIR)/libcustom.a $(OBJS)

# Build step for Cpp source
$(BUILD_DIR)/%.cc.o: %.cc
    @echo "__ Build Start __"
    mkdir -p $(dir $@)
    $(CC) $(CPPFLAGS) -c $< -o $@

.PHONY: clean
clean:
    rm -rf $(BUILD_DIR)

-include $(DEPS)

But I am getting a lot of syntax errors while making. Same errors I am getting when trying to build these files without a makefile also. The errors are:

".\tensorflow/lite/c/common.h", line 95: Error: #70: incomplete type is not allowed int data[]; ^ ".\tensorflow/lite/c/common.h", line 139: Error: #70: incomplete type is not allowed float data[]; ^ ".\tensorflow/lite/c/common.h", line 849: Warning: #368-D: class "TfLiteRegistrationExternal" defines no constructor to initialize the following: const member "TfLiteRegistrationExternal::version" typedef struct TfLiteRegistrationExternal { ^ "tensorflow/lite/c/common.cc", line 47: Warning: #550-D: variable "dummy" was set but never used static TfLiteIntArray dummy; ^ "tensorflow/lite/c/common.cc", line 59: Error: #20: identifier "nullptr" is undefined if (a == nullptr || b == nullptr) return 0; ^ "tensorflow/lite/c/common.cc", line 65: Error: #20: identifier "nullptr" is undefined if (a == nullptr) return (b_size == 0); ^ "tensorflow/lite/c/common.cc", line 77: Error: #20: identifier "nullptr" is undefined if (alloc_size <= 0) return nullptr; ^ "tensorflow/lite/c/common.cc", line 85: Error: #20: identifier "nullptr" is undefined if (!src) return nullptr; ^ "tensorflow/lite/c/common.cc", line 98: Warning: #550-D: variable "dummy" was set but never used static TfLiteFloatArray dummy; ^ "tensorflow/lite/c/common.cc", line 127: Error: #20: identifier "nullptr" is undefined t->data.raw = nullptr; ^ "tensorflow/lite/c/common.cc", line 136: Error: #20: identifier "nullptr" is undefined q_params->scale = nullptr; ^ "tensorflow/lite/c/common.cc", line 140: Error: #20: identifier "nullptr" is undefined q_params->zero_point = nullptr; ^ "tensorflow/lite/c/common.cc", line 144: Error: #20: identifier "nullptr" is undefined quantization->params = nullptr; ^ "tensorflow/lite/c/common.cc", line 149: Error: #20: identifier "nullptr" is undefined if (sparsity == nullptr) { ^ "tensorflow/lite/c/common.cc", line 184: Error: #20: identifier "nullptr" is undefined t->dims = nullptr; ^ "tensorflow/lite/c/common.cc", line 213: Error: #20: identifier "nullptr" is undefined tensor->quantization.params = nullptr; ^ "tensorflow/lite/c/common.cc", line 298: Error: #254: type name is not allowed TfLiteDelegate TfLiteDelegateCreate() { return TfLiteDelegate{}; } ^ "tensorflow/lite/c/common.cc", line 298: Error: #65: expected a ";" TfLiteDelegate TfLiteDelegateCreate() { return TfLiteDelegate{}; } ^ tensorflow/lite/c/common.cc: 3 warnings, 15 errors

I think I am doing something stupid somewhere. It would be very helpful if I get some direction on what is going wrong. Thanks in advance

fergushenderson commented 2 years ago

A simple fix for the warning

".\tensorflow/lite/c/common.h", line 849: Warning: #368-D: class "TfLiteRegistrationExternal" defines no constructor to initialize the following:

is to remove the 'const' from the 'version' member of TfLiteDelegateExternal.

For the other issues, the problem is that the C++ code that you are trying to build is written in a more modern dialect of C++ than is supported by the compiler that you are using, which is clearly pre-C++-2011 since it doesn't support 'nullptr'.

You might be able to make some progress by building with "-Dnullptr=0" in your compiler flags, and also adjusting the '#if' or '#elif' inside the definitions of TfLiteIntArray and TfLiteFloatArray in common.h to include suitable identifiers for your compiler.

Nafihahmd commented 2 years ago

Thanks a lot, the c++ compiler I am using is almost a decade old (maybe even more). Thanks for pointing me to the right direction. Let me see what I can do to solve it.

github-actions[bot] commented 1 year ago

"This issue is being marked as stale due to inactivity. Remove label or comment to prevent closure in 5 days."

github-actions[bot] commented 1 year ago

"This issue is being closed because it has been marked as stale for 5 days with no further activity."