ESP8266错误:宏“ min”传递了3个参数,但仅需2个

Éri*_*oGR 1 c++ compilation esp8266 arduino-esp8266 platformio

我正在使用PlatformIO用Arduino框架编译我的ESP8266(ESP12e)。在某些时候,如果按一定顺序使用#include,我会遇到错误。

下面是简化我的代码:

平台

[env:esp12e]
platform = espressif8266
board = esp12e
framework = arduino
upload_speed = 460800
Run Code Online (Sandbox Code Playgroud)

Teste.h

//#include <cstdlib> //<<--this
#include <cstring>   //<<-- and/or this causes error!
#include <Arduino.h>
#include <map>
Run Code Online (Sandbox Code Playgroud)

测试文件

#include "Teste.h"
void setup() {}
void loop() {}
Run Code Online (Sandbox Code Playgroud)

输出量

$ pio run
Please wait while upgrading PlatformIO ...
Updating atmelavr @ 1.3.1:  [Up-to-date]
Updating toolchain-atmelavr @ 1.40902.0:    [Up-to-date]
Updating framework-arduinoavr @ 1.10612.1:  [Up-to-date]
Updating espressif8266 @ 1.3.0:     [Up-to-date]
Updating toolchain-xtensa @ 1.40802.0:  [Up-to-date]
Updating tool-esptool @ 1.409.0:    [Up-to-date]
Updating tool-mkspiffs @ 1.102.0:   [Up-to-date]
Updating tool-espotapy @ 1.0.0:     [Up-to-date]
Updating framework-arduinoespressif8266 @ 1.20300.1:    [Up-to-date]
Updating sdk-esp8266 @ 1.10502.0:   [Up-to-date]
PlatformIO has been successfully upgraded to 3.2.1!

[Sun Dec 11 23:02:55 2016] Processing esp12e (platform: espressif8266, lib_deps: PubSubClient, upload_speed: 460800, board: esp12e, framework: arduino)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
Collected 24 compatible libraries
Looking for dependencies...
Library Dependency Graph
|-- <PubSubClient> v2.6
Compiling .pioenvs/esp12e/src/Teste.o
Archiving .pioenvs/esp12e/libFrameworkArduinoVariant.a
Indexing .pioenvs/esp12e/libFrameworkArduinoVariant.a
Compiling .pioenvs/esp12e/FrameworkArduino/Esp.o
In file included from /home/erico/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_tree.h:61:0,
from /home/erico/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/map:60,
from src/Teste.h:4,
from src/Teste.cpp:1:
/home/erico/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:239:56: error: macro "min" passed 3 arguments, but takes just 2
min(const _Tp& __a, const _Tp& __b, _Compare __comp)
^
/home/erico/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:260:56: error: macro "max" passed 3 arguments, but takes just 2
max(const _Tp& __a, const _Tp& __b, _Compare __comp)
^
Compiling .pioenvs/esp12e/FrameworkArduino/FS.o
Compiling .pioenvs/esp12e/FrameworkArduino/HardwareSerial.o
Compiling .pioenvs/esp12e/FrameworkArduino/IPAddress.o
In file included from src/Teste.h:3:0,
from src/Teste.cpp:1:
/home/erico/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:193:5: error: expected unqualified-id before 'const'
min(const _Tp& __a, const _Tp& __b)
^
/home/erico/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:193:5: error: expected ')' before 'const'
/home/erico/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:193:5: error: expected ')' before 'const'
/home/erico/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:193:5: error: expected initializer before 'const'
/home/erico/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:216:5: error: expected unqualified-id before 'const'
max(const _Tp& __a, const _Tp& __b)
^
/home/erico/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:216:5: error: expected ')' before 'const'
/home/erico/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:216:5: error: expected ')' before 'const'
/home/erico/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:216:5: error: expected initializer before 'const'
In file included from /home/erico/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_tree.h:61:0,
from /home/erico/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/map:60,
from src/Teste.h:4,
from src/Teste.cpp:1:
/home/erico/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:239:5: error: 'std::min' declared as an 'inline' variable
min(const _Tp& __a, const _Tp& __b, _Compare __comp)
^
/home/erico/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:239:5: error: template declaration of 'const _Tp& std::min'
/home/erico/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:242:7: error: expected primary-expression before 'if'
if (__comp(__b, __a))
^
/home/erico/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:242:7: error: expected '}' before 'if'
/home/erico/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:244:7: error: expected unqualified-id before 'return'
return __a;
^
/home/erico/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:260:5: error: 'max' declared as an 'inline' variable
max(const _Tp& __a, const _Tp& __b, _Compare __comp)
^
/home/erico/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:260:5: error: template declaration of 'const _Tp& max'
/home/erico/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:263:7: error: expected primary-expression before 'if'
if (__comp(__a, __b))
^
/home/erico/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:263:7: error: expected '}' before 'if'
/home/erico/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:265:7: error: expected unqualified-id before 'return'
return __a;
^
/home/erico/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:266:5: error: expected declaration before '}' token
}
^
Compiling .pioenvs/esp12e/FrameworkArduino/MD5Builder.o
Compiling .pioenvs/esp12e/FrameworkArduino/Print.o
*** [.pioenvs/esp12e/src/Teste.o] Error 1
============================================================================================ [ERROR] Took 0.47 seconds ============================================================================================
Run Code Online (Sandbox Code Playgroud)

我错过了什么?也许是Arduino Framework或Espressif SDK中的错误?

120*_*arm 5

<Arduino.h>报头定义maxmin宏。它确实不应该这样做。要解决该问题,请添加

#undef max
#undef min
Run Code Online (Sandbox Code Playgroud)

就在您的#include <Arduino.h>路线之后。