enfieldcat / ESP32_miniThrottle

ESP32 based JMRI WiThrottle with support for locomotives (rosters), turnouts and routes. Configurable ove serial connection. Uses Arduino IDE.
5 stars 2 forks source link

Compile error #1

Closed steampunklolcat closed 12 months ago

steampunklolcat commented 1 year ago

I keep getting the below error when trying to compile the project for a Lolin D32 esp32 board. It happens with both the 0.4 and the 0.5 versions of the throttle.

`In file included from /Users/morten/Documents/Arduino/libraries/lcdgfx/src/lcdgfx.h:30, from /Users/morten/Documents/Creative Projects/arduino/ESP32_miniThrottle/static_defs.h:9, from /Users/morten/Documents/Creative Projects/arduino/ESP32_miniThrottle/ESP32_miniThrottle.ino:6: /Users/morten/Library/Arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/gcc8_4_0-esp-2021r2-patch3/xtensa-esp32-elf/include/c++/8.4.0/bits/stl_vector.h: In member function 'std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::_M_check_len(std::vector<_Tp, _Alloc>::size_type, const char*) const': /Users/morten/Documents/Arduino/libraries/lcdgfx/src/nano_gfx_types.h:41:19: error: expected unqualified-id before '(' token

define max(a, b) ((a) > (b) ? (a) : (b))

               ^

/Users/morten/Library/Arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/gcc8_4_0-esp-2021r2-patch3/xtensa-esp32-elf/include/c++/8.4.0/bits/stl_bvector.h: In member function 'std::vector<bool, _Alloc>::size_type std::vector<bool, _Alloc>::_M_check_len(std::vector<bool, _Alloc>::size_type, const char*) const': /Users/morten/Documents/Arduino/libraries/lcdgfx/src/nano_gfx_types.h:41:19: error: expected unqualified-id before '(' token

define max(a, b) ((a) > (b) ? (a) : (b))

               ^

exit status 1

Compilation error: exit status 1`

enfieldcat commented 1 year ago

This is not a known issue.

Did the code compile without modifying any miniThrottle.h settings?

If you changed any of the settings can you let me know what they were so I can try to reproduce the issue?

Alternatively given the location of the code in /Arduino/libraries/lcdgfx/src/nano_gfx_types.h it may be an issue in lcdgfx. Is there any simple lcdgfx demo code you can compile without error? If you encounter an issue with the lcdgfx demo code then the issue may lie with their code.

steampunklolcat commented 1 year ago

I just tried on another machine as a test.

  1. Download version 2.0.1 of the Arduino IDE.
  2. Added the esp32 board url and installed the esp32 support.

https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

  1. Added the needed libraries: keypad, esp32encoder and lcdgfx. Keypad - 3.1.1 Esp32Encoder - 0.10.1 lcdgfx - 1.1.4

  2. Selected the Lolin D32 board.

I can compile the lcdgfx/demos/ssd1306_demo sketch without errors.

Version 0.4 downloaded from https://conferre.cf/miniThrottle/miniThrottle.zip and minithrottle.h copied from the example file produces the output below.

`In file included from c:\Users\morten\Documents\Arduino\libraries\lcdgfx\src/lcdgfx.h:30, from C:\Users\morten\Documents\Arduino\ESP32_miniThrottle\miniThrottle.h:8, from C:\Users\morten\Documents\Arduino\ESP32_miniThrottle\ESP32_miniThrottle.ino:5: c:\users\morten\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\gcc8_4_0-esp-2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\bits\stl_vector.h: In member function 'std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::_M_check_len(std::vector<_Tp, _Alloc>::size_type, const char*) const': c:\Users\morten\Documents\Arduino\libraries\lcdgfx\src/nano_gfx_types.h:41:19: error: expected unqualified-id before '(' token

define max(a, b) ((a) > (b) ? (a) : (b))

               ^

c:\users\morten\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\gcc8_4_0-esp-2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\bits\stl_bvector.h: In member function 'std::vector<bool, _Alloc>::size_type std::vector<bool, _Alloc>::_M_check_len(std::vector<bool, _Alloc>::size_type, const char*) const': c:\Users\morten\Documents\Arduino\libraries\lcdgfx\src/nano_gfx_types.h:41:19: error: expected unqualified-id before '(' token

define max(a, b) ((a) > (b) ? (a) : (b))

               ^

exit status 1

Compilation error: exit status 1`

enfieldcat commented 1 year ago

The compiler I have hasn't been updated in some time.

I've tested compilation on Windows with: Arduino 1.8.19 (Windows Store 1.8.57.0) And on Raspberry-Pi Linux with the CLI version of Arduino

  1. arduino-cli alpha Version: 0.14.1 Commit: 0284b57a Date: 2021-01-27T09:54:52Z
  2. arduino-cli Version: 0.28.0 Commit: 06fb1909 Date: 2022-10-20T08:42:19Z

These three compile OK on my system. I may need a few days to download / test using a newer Windows or Linux graphical interface to see if I can replicate and resolve the issue.

enfieldcat commented 1 year ago

The CLI environment shows the following library versions in use, again they are most likely not the latest. Used library Version Path lcdgfx 1.1.4 /home/enfield/Arduino/libraries/lcdgfx SPI 1.0 /home/enfield/.arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/SPI Keypad 3.1.1 /home/enfield/Arduino/libraries/Keypad ESP32Encoder 0.9.1 /home/enfield/Arduino/libraries/ESP32Encoder Preferences 1.0 /home/enfield/.arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/Preferences WiFi 1.0 /home/enfield/.arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/WiFi ESPmDNS 1.0 /home/enfield/.arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/ESPmDNS HTTPClient 1.2 /home/enfield/.arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/HTTPClient WiFiClientSecure 1.0 /home/enfield/.arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/WiFiClientSecure FS 1.0 /home/enfield/.arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/FS SPIFFS 1.0 /home/enfield/.arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/SPIFFS Wire 1.0.1 /home/enfield/.arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/Wire

Used platform Version Path esp32:esp32 1.0.6 /home/enfield/.arduino15/packages/esp32/hardware/esp32/1.0.6

steampunklolcat commented 1 year ago

I got it to compile now using the same versions as you for the esp32encoder library and the esp32 platform. Afterwards I tested with upgrading the esp32 platform to version 2.0 and that broke it.

PS C:\Users\morten\Documents\Arduino> arduino-cli compile --fqbn esp32:esp32:lolin32:CPUFreq=80,PartitionScheme=min_spiffs ESP32_miniThrottle Sketch uses 1049606 bytes (53%) of program storage space. Maximum is 1966080 bytes. Global variables use 42904 bytes (13%) of dynamic memory, leaving 284776 bytes for local variables. Maximum is 327680 bytes.

Used library Version Path lcdgfx 1.1.4 C:\Users\morten\Documents\Arduino\libraries\lcdgfx SPI 1.0 C:\Users\morten\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\SPI Keypad 3.1.1 C:\Users\morten\Documents\Arduino\libraries\Keypad ESP32Encoder 0.9.1 C:\Users\morten\Documents\Arduino\libraries\ESP32Encoder Preferences 1.0 C:\Users\morten\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\Preferences WiFi 1.0 C:\Users\morten\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\WiFi ESPmDNS 1.0 C:\Users\morten\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\ESPmDNS HTTPClient 1.2 C:\Users\morten\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\HTTPClient WiFiClientSecure 1.0 C:\Users\morten\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\WiFiClientSecure FS 1.0 C:\Users\morten\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\FS SPIFFS 1.0 C:\Users\morten\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\SPIFFS Wire 1.0.1 C:\Users\morten\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\Wire

Used platform Version Path esp32:esp32 1.0.6 C:\Users\morten\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6

enfieldcat commented 1 year ago

That is interesting! After a fresh install of the environment (to exclude any previous tweaks I may have had in my system) and using platform 2.0.5 I could replicate the error. Confirming the issue is related to platform upgrade. Some further "Google-Research" later... and I the code compiled after commenting out the offending lines in

But, I've not flashed that to a test unit to check if it works. - just because it compiles doesn't mean it will work!

So what lead me to fiddle in lcdgfx's code? A quote old bugzilla posting: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=16605 (comment 5) which suggests:

Your code defines min/max as macros. The preprocessor expands this, which leaves what used to be std::max(x1, x2) as something that doesn't make much sense to the compiler any more.

Since the standard says that the names min/max are reserved, simply remove these #defines from your sources.

Probably the new platform better implements / enforces at standard that uses min and max as expansions that then renders the original code meaningless to the compiler. But I'd rather leave that determination / fix to the lcdgfx project. Until then I would recommend sticking to platform 1.0.6.

enfieldcat commented 1 year ago

Created lcdgfx issue: https://github.com/lexus2k/lcdgfx/issues/94

enfieldcat commented 12 months ago

The cause of this issue has been tracked to using http client with lcdgfx. In the development version there is now a "#define NOHTTPCLIENT 1" option that can be added to miniThrottle.h - this will disable the http client on the miniThrottle build: effectively you can't download config files or OTA updates to the device. It will still support the HTTP configuration server.