You can chat about native SDK questions and issues here.

User avatar
By jbsimon000
#94723 I am attempting to run some C++ code on ESP8266. I stared with the "hello world" example and renamed hello_world_main.c to hello_world_main.cpp, and changed it as shown below. It builds fine and I flash it to my board using "make flash". When I run it I get the errors shown at the bottom of this post.

Building on Ubuntu Linux,
Toolchain version: esp-2020r3-49-gd5524c1
Compiler version: 8.4.0

Code: Select all#include <iostream>
using namespace std;
extern "C" void app_main() ;
 
void app_main()
{
  cout << "Starting Test" << endl ;
}


if I change the "#include <iostream>" to "#include <stdio.h>" and change the "cout" to a "printf" it runs as expected.

The errors I am seeing are as follows:

[size=50]2nd stage bootloader
I (64) boot: compile time 18:37:03
I (75) qio_mode: Enabling default flash chip QIO
I (75) boot: SPI Speed : 40MHz
I (75) boot: SPI Mode : QIO
I (78) boot: SPI Flash Size : 4MB
I (82) boot: Partition Table:
I (86) boot: ## Label Usage Type ST Offset Length
I (93) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (100) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (108) boot: 2 factory factory app 00 00 00010000 000f0000
I (116) boot: End of partition table
I (120) esp_image: segment 0: paddr=0x00010010 vaddr=0x40210010 size=0x3f844 (260164) map
0x40210010: _stext at ??:?

I (217) esp_image: segment 1: paddr=0x0004f85c vaddr=0x4024f854 size=0x20c7c (134268) map
I (264) esp_image: segment 2: paddr=0x000704e0 vaddr=0x3ffe8000 size=0x004b8 ( 1208) load
I (264) esp_image: segment 3: paddr=0x000709a0 vaddr=0x40100000 size=0x00080 ( 128) load
I (271) esp_image: segment 4: paddr=0x00070a28 vaddr=0x40100080 size=0x04874 ( 18548) load
I (286) boot: Loaded app from partition at offset 0x10000
Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x40246630 PS : 0x00000030 A0 : 0x40213361 A1 : 0x3ffe9330
0x40246630: vListInsert at /home/dada/esp8266/ESP8266_RTOS_SDK/components/freertos/freertos/list.c:150 (discriminator 1)

0x40213361: vTaskPlaceOnEventList at /home/dada/esp8266/ESP8266_RTOS_SDK/components/freertos/freertos/tasks.c:2960

A2 : 0x40107630 A3 : 0x3ffeb878 A4 : 0x00000000 A5 : 0x40107638
A6 : 0x00000000 A7 : 0x0000000e A8 : 0x00000000 A9 : 0x00000000
A10 : 0x00000000 A11 : 0x00000000 A12 : 0xffffffff A13 : 0x00000001
A14 : 0x00000000 A15 : 0x00000001 SAR : 0x00000000 EXCCAUSE: 0x0000001c

Backtrace: 0x40246630:0x3ffe9330 0x40213361:0x3ffe9330 0x40212a92:0x3ffe9340 0x4021a5b7:0x3ffe9370 0x4021a775:0x3ffe9380 0x4021c9bd:0x3ffe9390 0x4021d39b:0x3ffe93a0 0x4021d3b8:0x3ffe93c0 0x4021d4a7:0x3ffe93d0 0x4022d4f2:0x3ffe93e0 0x4021c9d5:0x3ffe9400 0x4021d3d7:0x3ffe9410 0x4022d4bb:0x3ffe9430 0x4022d502:0x3ffe9440 0x4021c9d5:0x3ffe9460 0x4021d3d7:0x3ffe9470 0x4022d4bb:0x3ffe9490 0x4022d502:0x3ffe94a0 0x4021c9d5:0x3ffe94c0 0x4021d3d7:0x3ffe94d0 0x4022d4bb:0x3ffe94f0 0x4022d502:0x3ffe9500 0x4021c9d5:0x3ffe9520 0x4021d3d7:0x3ffe9530 0x4022d4bb:0x3ffe9550 0x4022d502:0x3ffe9560 0x4021c9d5:0x3ffe9580 0x4021d3d7:0x3ffe9590 0x4022d4bb:0x3ffe95b0 0x4022d502:0x3ffe95c0 0x4021c9d5:0x3ffe95e0 0x4021d3d7:0x3ffe95f0 0x4022d4bb:0x3ffe9610 0x4022d502:0x3ffe9620 0x4021c9d5:0x3ffe9640 0x4021d3d7:0x3ffe9650 0x4022d4bb:0x3ffe9670 0x4022d502:0x3ffe9680 0x4021c9d5:0x3ffe96a0 0x4021d3d7:0x3ffe96b0 0x4022d4bb:0x3ffe96d0 0x4022d502:0x3ffe96e0 0x4021c9d5:0x3ffe9700 0x4021d3d7:0x3ffe9710 0x4022d4bb:0x3ffe9730 0x4022d502:0x3ffe9740 0x4021c9d5:0x3ffe9760 0x4021d3d7:0x3ffe9770 0x4022d4bb:0x3ffe9790 0x�0x40246630: vListInsert at /home/dada/esp8266/ESP8266_RTOS_SDK/components/freertos/freertos/list.c:150 (discriminator 1)

0x40213361: vTaskPlaceOnEventList at /home/dada/esp8266/ESP8266_RTOS_SDK/components/freertos/freertos/tasks.c:2960

0x40212a92: xQueueSemaphoreTake at /home/dada/esp8266/ESP8266_RTOS_SDK/components/freertos/freertos/queue.c:1557

0x4021a5b7: pthread_mutex_lock_internal at /home/dada/esp8266/ESP8266_RTOS_SDK/components/pthread/pthread.c:608

0x4021a775: pthread_mutex_lock at /home/dada/esp8266/ESP8266_RTOS_SDK/components/pthread/pthread.c:638

0x4021c9bd: __gnu_cxx::__mutex::lock() at /builds/idf/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/ext/concurrence.h:152

0x4021d39b: std::get_terminate() at /builds/idf/crosstool-NG/.build/xtensa-lx106-elf/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:95

0x4021d3b8: std::terminate() at /builds/idf/crosstool-NG/.build/xtensa-lx106-elf/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:57

0x4021d4a7: __gthread_setspecific at /builds/idf/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/xtensa-lx106-elf/bits/gthr-default.h:738 (discriminator 2)
(inlined by) __cxa_get_globals at /builds/idf/crosstool-NG/.build/xtensa-lx106-elf/src/gcc/libstdc++-v3/libsupc++/eh_globals.cc:132 (discriminator 2)

0x4022d4f2: __cxa_throw at /builds/idf/crosstool-NG/.build/xtensa-lx106-elf/src/gcc/libstdc++-v3/libsupc++/eh_throw.cc:81

0x4021c9d5: __gnu_cxx::__mutex::lock() at /builds/idf/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/ext/concurrence.h:156

0x4021d3d7: std::get_unexpected() at /builds/idf/crosstool-NG/.build/xtensa-lx106-elf/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:122

0x4022d4bb: __cxa_init_primary_exception at /builds/idf/crosstool-NG/.build/xtensa-lx106-elf/src/gcc/libstdc++-v3/libsupc++/eh_throw.cc:66

0x4022d502: __cxa_throw at /builds/idf/crosstool-NG/.build/xtensa-lx106-elf/src/gcc/libstdc++-v3/libsupc++/eh_throw.cc:85

0x4021c9d5: __gnu_cxx::__mutex::lock() at /builds/idf/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/ext/concurrence.h:156
[/size]

The errors starting at concurrence.h:156 keep repeating until the module reboots giving the same results.
User avatar
By jbsimon000
#94757 It appears that as soon as I include <iostream> the error is encountered, and it looks like the stack is getting blown up.

For instance, the following builds and runs, but if the only change I make is to uncomment the #include <iostream> line, boom !

Code: Select all  #include <stdio.h>
  #include <string>
//  #include <iostream>
 
  extern "C" void app_main() ;

  void app_main()
  {
    std::string myStr ( "Starting Test, 1.2.3.4." ) ;
    printf ( "%s\n", myStr.c_str() ) ;
  }