@tcontrada You can modify where we call this (the source of all files is in the libraries folder of the IDE, e.g. ~/Documents/Arduino/libraries/
on macOS), would be interested to see if that helps, but std::fmax
is valid and part of cmath (see https://en.cppreference.com/w/cpp/numeric/math/fmax).
@tcontrada. I had the same issue but I found a solution after reading this forum.
Now I have another issue that “The filename or extension is too long.” I have yet to solve this problem or find a solution.
@electronictechgreg interesting though, we bundle a distribution of TensorFlow Lite in the Arduino library… The filename is too long is described here: https://docs.edgeimpulse.com/docs/running-your-impulse-arduino#code-compiling-fails-under-windows-os by @aurel
I’ve fixed that issue a while back after reading your documentation. But I got another issue which is below.
fork/exec C:\Users\elect\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-80-g6c4433a-5.2.0/bin/xtensa-esp32-elf-gcc.exe: The filename or extension is too long.
That’s a similar issue but as it’s a different compiler, you’ll need another platform.local.txt to fix it. I’ll try to have a look at it.
FYI there is a pull request on the Arduino side but it’s still in progress: https://github.com/arduino/arduino-cli/pull/961
Aurelien
Looking at the esp32 recipe you should not reach the 32k max characters while compiling but you may have some filenames over 260 characters.
Could you try changing the MAX_PATH under your Windows OS? https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
Aurelien
I just purchased a new PC as of last night. My old laptop was failing. I will let you know how I make out once I get everything installed. Thank you for your help.
I understand that std::fmax is part of cmath, but when I look at one of your header file it references math.h instead.
I really don’t want to have to troubleshoot all your dependency files to solve this problem. I would think you might have a conflicting reference problem that most likely needs to be resolved.
If you guys don’t want to help, then I will move on to another ML application…
Thanks,
Tony
Hi @tcontrada, please understand that we’d love to help you, but it’s hard when we cannot replicate the error, either on the ESP32 or on a different development board.
We reference cmath
here, also the only place where we use std::fmax
: https://github.com/edgeimpulse/inferencing-sdk-cpp/blob/67f085eb39033edf80e1ea8e41f5c089b65187e3/tensorflow/lite/kernels/internal/max.h#L18
If you’d be interested you can find this file in the Arduino library folder, and replace it with:
/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_MAX_H_
#define TENSORFLOW_LITE_KERNELS_INTERNAL_MAX_H_
#include <cmath>
namespace tflite {
inline float TfLiteMax(const float& x, const float& y) {
return std::max(x, y);
}
} // namespace tflite
#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_MAX_H_
This will always default to std::max
, but my feeling is there might be something wrong deeper so you’ll probably run into another error at a later point.
@tcontrada. If you went to the website I provided yesterday you would have seen they were talking about the same issue you are having. They edited the file “max.h” and added || defined(ARDUINO) as shown below. They did the same with min.h. This should resolve the issue that you are having.
#if defined(TF_LITE_USE_GLOBAL_MAX) defined(ZEPHYR)
|| defined(ARDUINO)
inline float TfLiteMax(const float& x, const float& y) {
return std::max(x, y);
}
#else
template
inline T TfLiteMax(const T& x, const T& y) {
return std::fmax(x, y);
}
#endif
Hi, yes that did fix the compile issue. But I have the long filename issue now.
I did the RegEdit for allowing long file names, but still get the error.
I saw the post about adding the platform.local.txt file to this folder,
C:\Users\MYUSER\AppData\Local\Arduino15\packages\arduino\hardware\mbed\1.1.4\
The problem is I don’t have an mbed folder along that path!!
Yes, I did state that I have the long file problem after the fmax fmin fix. I have yet to find a solution but my laptop died. So I will have to try with the new laptop when I get time. But aurel said he was going to look into the issue and find a solution.
The platform.local.txt solution works for Arduino Nano boards, I’ll boot a Windows OS tomorrow to check more deeply.
But you can already try this:
This should bypass the compiling issue but you might still having an issue during linking.
Aurelien
@electronictechgreg @tcontrada I missed the link @electronictechgreg added, but great! I’ll make sure we set that define on ESP32 targets in the future.
@aurel I tried as you asked.
I set LongPathsEnabled
to 1 in the registry and rebooted my PC. I tried to recompile the sketch but sill get the same error.
fork/exec C:\Users\Greg\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-80-g6c4433a-5.2.0/bin/xtensa-esp32-elf-gcc.exe: The filename or extension is too long.
Same here… Waiting for a fix, I hope!!
I tried with Visual Studio Code and Platformio just to try to see if it will compile. I don’t know much about how to use this compiler but I received the error below.
test_project_inference.h: No such file or directory
But I will wait for a solution in the mean time for the Arduino IDE. A solution wll eventually come about.
I managed to compile under the Arduino IDE, basically putting all object files in an archive to bypass the Windows command line issue.
You can create a platform.local.txt file under the ESP32 target folder (C:\Users\MYUSER\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4) with the following content:
## Customized platform.local.txt to compile for ESP32 targets under Windows
## This recipe works around the Windows limit of 32k characters in a cmd line by calling .o files from a text file during linking
## Install: put file under your esp32 sub-directory - ie:C:\Users\MYUSER\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4
## You can also find the local arduino folder in the IDE under File -> Preferences -> see preferences.txt location in the bottom part of the window
## hooks
# create a txt file with all object file paths from libraries and sketch folders
recipe.hooks.linking.prelink.1.pattern=cmd /c dir /b /s {build.path}\sketch\*.o > {build.path}\obj_files_tmp.txt
recipe.hooks.linking.prelink.2.pattern=cmd /c "dir /b /s {build.path}\libraries\*.o >> {build.path}\obj_files_tmp.txt 2>nul & exit 0"
# replace \ by \\ in file paths (otherwise escaped by linker) and save in new txt file
recipe.hooks.linking.prelink.3.pattern=cmd /v /c "@echo off && for /f %a in ({build.path}\obj_files_tmp.txt) do (set line=%a && set line=!line:\=\\! && echo !line! >> {build.path}\obj_files.txt)"
# save object files in archive
recipe.hooks.linking.prelink.4.pattern=cmd /v /c "@echo off && for /f %a in ({build.path}\obj_files.txt) do ({compiler.path}{compiler.ar.cmd} {compiler.ar.flags} {compiler.ar.extra_flags} {build.path}\custom_lib.a %a)"
# delete txt file and archive after linking
recipe.hooks.linking.postlink.1.pattern=cmd /c del {build.path}\obj_files.txt
recipe.hooks.linking.postlink.2.pattern=cmd /c del {build.path}\custom_lib.a
## modify compile patterns (use custom_lib.a instead of object_files)
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -Wl,--start-group "{build.path}\custom_lib.a" "{archive_file_path}" {compiler.c.elf.libs} -Wl,--end-group -Wl,-EL -o "{build.path}/{build.project_name}.elf"
Let me know if that works for you.
Aurelien