2

PlatformIO を使用して ESP8266 (ESP12e) を Arduino フレームワークでコンパイルしています。#includeを特定の順序で使用すると、特定の時点でエラーが発生します。

以下は私のコードを簡略化したものです:

platformio.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 フレームワークまたは Espressif SDK のバグでしょうか?

4

1 に答える 1

7

<Arduino.h>ヘッダーはマクロを定義しますmaxminそれは本当にすべきではありません。この問題を回避するには、追加します

#undef max
#undef min

#include <Arduino.h>あなたの行の直後。

于 2016-12-12T04:10:20.767 に答える