2

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

下面是简化我的代码:

平台io.ini

[env:esp12e]
platform = espressif8266
board = esp12e
framework = arduino
upload_speed = 460800

Teste.h

//#include <cstdlib> //<<--this
#include <cstring>   //<<-- and/or this causes error!
#include <Arduino.h>
#include <map>

Teste.cpp

#include "Teste.h"
void setup() {}
void loop() {}

输出

$ 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 ============================================================================================

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

4

1 回答 1

7

<Arduino.h>头定义maxmin宏。它真的不应该那样做。要解决此问题,请添加

#undef max
#undef min

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

于 2016-12-12T04:10:20.767 回答