Project build fails after latest updates

Hi! I opened my project after a few days tried to recompile without changes and I got the errors below (it’s a partial copy and paste, btw, copying from the terminal doesn’t work properly)

Any clues?
Cheers

Currently on PlatformIO 4.0.0

Processing due (platform: atmelsam; board: due; framework: arduino)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelsam/due.html
PLATFORM: Atmel SAM 3.8.0 > Arduino Due (Programming Port)
HARDWARE: AT91SAM3X8E 84MHz, 96KB RAM, 512KB Flash

DEBUG: Current (atmel-ice) External (atmel-ice, blackmagic, jlink, stlink)
PACKAGES: toolchain-gccarmnoneeabi 1.70201.0 (7.2.1), framework-arduinosam 4.3.190711
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 5 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <ArduinoJson> 6.11.2 #815326d
|-- <MIDIUSB> 1.0.4
Compiling .pio/build/due/src/ControlChange.cpp.o
Compiling .pio/build/due/src/Note.cpp.o
Compiling .pio/build/due/src/Patch.cpp.o
Compiling .pio/build/due/src/main.cpp.o
In file included from /Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/char_traits.h:39:0,
                 from /Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/string:40,
                 from src/MidiEvent.h:3,
                 from src/ControlChange.h:3,
                 from src/ControlChange.cpp:2:
/Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:243:56: error: macro "min" passed 3 arguments, but takes just 2
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
                                                        ^
/Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:265:56: error: macro "max" passed 3 arguments, but takes just 2
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
                                                        ^
In file included from /Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/char_traits.h:39:0,
                 from /Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/string:40,
                 from src/MidiEvent.h:3,
                 from src/Note.h:3,
                 from src/Note.cpp:1:
/Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:243:56: error: macro "min" passed 3 arguments, but takes just 2
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
                                                        ^
/Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:265:56: error: macro "max" passed 3 arguments, but takes just 2
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
                                                        ^
In file included from /Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/char_traits.h:39:0,
                 from /Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/string:40,
                 from src/MidiEvent.h:3,
                 from src/Note.h:3,
                 from src/Patch.h:3,
                 from src/Patch.cpp:1:
/Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:243:56: error: macro "min" passed 3 arguments, but takes just 2
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
     /Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:265:56: error: macro "max" passed 3 arguments, but takes just 2
          max(const _Tp& __a, const _Tp& __b, _Compare __comp)
                                                             ^
     In file included from /Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/char_traits.h:39:0,
                      from /Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/string:40,
                      from src/config.h:1,
                      from src/main.cpp:6:
     /Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:243:56: error: macro "min" passed 3 arguments, but takes just 2
          min(const _Tp& __a, const _Tp& __b, _Compare __comp)
                                                             ^
     /Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:265:56: error: macro "max" passed 3 arguments, but takes just 2
          max(const _Tp& __a, const _Tp& __b, _Compare __comp)
                                                             ^
     In file included from /Users/aekidna/.platformio/packages/framework-arduinosam/system/sam/libsam/chip.h:66:0,
                      from /Users/aekidna/.platformio/packages/framework-arduinosam/cores/sam/Arduino.h:42,
                      from src/ControlChange.cpp:1:
     /Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:195:5: error: expected unqualified-id before 'const'
          min(const _Tp& __a, const _Tp& __b)
          ^
     /Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:195:5: error: expected ')' before 'const'
     /Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:195:5: error: expected ')' before 'const'
     /Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:195:5: error: expected ')' before 'const'
     /Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:195:5: error: expected initializer before 'const'
     /Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:219:5: error: expected unqualified-id before 'const'
          max(const _Tp& __a, const _Tp& __b)
          ^
     /Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:219:5: error: expected ')' before 'const'
     /Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:219:5: error: expected ')' before 'const'
     /Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:219:5: error: expected ')' before 'const'
     /Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:219:5: error: expected initializer before 'const'
     In file included from /Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/bits/char_traits.h:39:0,
                      from /Users/aekidna/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/7.2.1/string:40,
                      from src/MidiEvent.h:3,
                      from src/ControlChange.h:3,
                      from src/ControlChange.cpp:2:

Do you have macros min and max defined in your code?

It very much looks as if somewhere in your code or in one of the libraries, a macro with two arguments is defined, e.g.:

#define min(a, b) (a < b ? a : b)
#define min(a, b) (a > b ? a : b)

That’s in conflict with the standard C++ library using several functions called min and max. And as macros are a very crude mechanism, they will be applied in that code as well and will cause problems.

I quickly checked the source code of ArduinoJson and * MIDIUSB* and – if I’ve looked at the correct libraries – they don’t define such macros.

1 Like

Thanks for the reply.

No, there is no definition of min or max.

Before posting here I found this c++ - ESP8266 error: macro "min" passed 3 arguments, but takes just 2 - Stack Overflow

Arduino.h defines min and max. The stackoverflow replies suggest to add

#undef max
#undef min

after #include <Arduino.h>

I did but not everywhere, hence the errors.

What misled me is the errors that appear further down that didn’t seem to make much sense.

So, now the project is building. I have no idea whether Arduino.h recently added those definitions or the toolchain is now somewhat less tolerant.

Not sure what’s going on there… the definition of the min and max macros is not actually done by Arduino.h in this case. It is on the AVR platform, but seems to have been for quite a while… longer than I would have thought actually, as I remember Adafruit docs showing it needed to be defined… but anyway, github history is showing it’s been there since at Mar 2011 for arduino-avr… and for atmel-sam it’s in USB_device.h which hasn’t been touched since 2012…