ESP8266在Arduino IDE(xtensa-lx106-elf-gcc)和std::map链接错误问题

5

是否可能在Arduino包的ESP8266上使用map呢?

这是我的代码:

#include <map>

typedef std::map<int, int> Items;

void setup() {
  Items items;
  items[2]=5;
  //items.emplace(4,5);
}

void loop() {

}

这里是编译/链接错误:

Arduino: 1.6.5 (Windows 8.1), Board: "Generic ESP8266 Module, Serial, 80 MHz, 40MHz, DIO, 115200, 512K (64K SPIFFS)"

sketch_oct31a.cpp.o: In function `loop':
C:\Program Files (x86)\Arduino/sketch_oct31a.ino:11: undefined reference to     `std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*,     std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)'
sketch_oct31a.cpp.o: In function `_M_emplace_hint_unique<const     std::piecewise_construct_t&, std::tuple<int&&>, std::tuple<> >':
c:\users\user\appdata\roaming\arduino15\packages\esp8266\tools\xtensa-lx106-    elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-    elf\include\c++\4.8.2\bits/stl_tree.h:1673: undefined reference to     `std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*,     std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)'
sketch_oct31a.cpp.o: In function `std::_Rb_tree<int, std::pair<int const,     int>, std::_Select1st<std::pair<int const, int> >, std::less<int>,     std::allocator<std::pair<int const, int> >     >::_M_erase(std::_Rb_tree_node<std::pair<int const, int> >*)':
c:\users\user\appdata\roaming\arduino15\packages\esp8266\tools\xtensa-lx106-    elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-    elf\include\c++\4.8.2\bits/stl_tree.h:1130: undefined reference to     `std::_Rb_tree_decrement(std::_Rb_tree_node_base*)'
sketch_oct31a.cpp.o: In function `std::_Rb_tree_iterator<std::pair<int     const, int> >::operator--()':
c:\users\user\appdata\roaming\arduino15\packages\esp8266\tools\xtensa-lx106-    elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-    elf\include\c++\4.8.2\bits/stl_tree.h:204: undefined reference to     `std::_Rb_tree_decrement(std::_Rb_tree_node_base*)'
sketch_oct31a.cpp.o:    (.text._ZNSt8_Rb_treeIiSt4pairIKiiESt10_Select1stIS2_ESt4lessIiESaIS2_EE29_M_get    _insert_hint_unique_posESt23_Rb_tree_const_iteratorIS2_ERS1_[_ZNSt8_Rb_treeIiSt4    pairIKiiESt10_Select1stIS2_ESt4lessIiESaIS2_EE29_M_get_insert_hint_unique_posESt    23_Rb_tree_const_iteratorIS2_ERS1_]+0x0): undefined reference to `std::_Rb_tree_increment(std::_Rb_tree_node_base*)'
sketch_oct31a.cpp.o: In function `std::_Rb_tree<int, std::pair<int const,     int>, std::_Select1st<std::pair<int const, int> >, std::less<int>,     std::allocator<std::pair<int const, int> >     >::_M_get_insert_hint_unique_pos(std::_Rb_tree_const_iterator<std::pair<int     const, int> >, int const&)':
c:\users\user\appdata\roaming\arduino15\packages\esp8266\tools\xtensa-lx106-    elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2\bits/stl_tree.h:1431: undefined reference to `std::_Rb_tree_decrement(std::_Rb_tree_node_base*)'
c:\users\user\appdata\roaming\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2\bits/stl_tree.h:1448: undefined reference to `std::_Rb_tree_increment(std::_Rb_tree_node_base*)'
collect2.exe: error: ld returned 1 exit status
Error compiling.

我从这里获取了该软件包:https://github.com/esp8266/Arduino。顺便说一句,其他ESP8266的软件都可以编译通过。谢谢。

loop是否完全为空? - bluefog
是的,这只是一个简短的演示。 - x_arrange
2个回答

7
标准的ESP8266设置不链接libstdc++,这会提供map和其他std命名空间代码。
您需要编辑位于ESP8266 Arudino文件夹根目录下的platforms.txt(此文件夹的位置取决于安装程序和操作系统)-并将-lstdc++添加到以下行:
compiler.c.elf.libs=-lm -lgcc -lhal -lphy -lnet80211 -llwip -lwpa -lmain -lpp -lsmartconfig -lwps -lcrypto -laxtls

Arduino IDE 只在启动时读取此文件,因此在编译之前请确保重新启动IDE。


Minon,在 $ARDUINO_IDE/hardware/ 目录下没有名为 esp8266com 的文件夹。 - mR.aTA
你说得对,这只存在于我使用git版本并为其开发的情况下。由于每个安装方法和操作系统的安装都会有所不同,我已经删除了路径,读者将不得不确定他们安装软件包的位置。 - Dawn Minion

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接