Discuss here different C compiler set ups, and compiling executables for the ESP8266

User avatar
By jcmvbkbc
#2584
jcmvbkbc wrote:
joostn wrote:Can anyone help me out? BTW I don't need the C++ standard libraries, I just need to be able to work with my own C++ classes.

Let me look a bit more at our startup sequence...


Ok, there may be straighter ways of doing that, but the easiest that I've found is that: add the following code to your user_main:
(UPD: the original code did wrong constructors array address calculation, thanks to igrr for pointing it. Below is the fixed version.)

Code: Select allextern void (*__init_array_start)(void);
extern void (*__init_array_end)(void);

static void do_global_ctors(void)
{
        void (**p)(void);
        for (p = &__init_array_start; p != &__init_array_end; ++p)
                (*p)();
}

extern "C" void user_init(void)
{
        do_global_ctors();
}


And the following three lines to your linker script:
Code: Select all--- eagle.app.v6.ld.orig        2014-10-24 16:51:40.000000000 +0300
+++ eagle.app.v6.ld     2014-11-14 02:31:13.658457791 +0300
@@ -96,11 +96,14 @@
     *(.gnu.linkonce.e.*)
     *(.gnu.version_r)
     *(.eh_frame)
+    . = (. + 3) & ~ 3;
     /*  C++ constructor and destructor tables, properly ordered:  */
+    __init_array_start = ABSOLUTE(.);
     KEEP (*crtbegin.o(.ctors))
     KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
     KEEP (*(SORT(.ctors.*)))
     KEEP (*(.ctors))
+    __init_array_end = ABSOLUTE(.);
     KEEP (*crtbegin.o(.dtors))
     KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
     KEEP (*(SORT(.dtors.*)))
Last edited by jcmvbkbc on Fri Nov 21, 2014 3:15 am, edited 1 time in total.
User avatar
By joostn
#2592 Thanks a lot!! Will try this after the weekend.
User avatar
By igrr
#2995 @jcmvbkbc
I've got linker errors that happen for some pieces of c++ code, but not for others. Not sure what exactly is triggering them.
While I'm trying to figure out the minimal example to reproduce those, could you please take a look at the errors?
Code: Select all/var/folders/15/ybtbgzpj7636vv4wp92l2c700000gn/T/build859463475789359941.tmp/core.a(HardwareSerial.cpp.o):(.rodata._ZTI6Stream[typeinfo for Stream]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
/var/folders/15/ybtbgzpj7636vv4wp92l2c700000gn/T/build859463475789359941.tmp/core.a(HardwareSerial.cpp.o):(.rodata._ZTI14HardwareSerial[typeinfo for HardwareSerial]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
/var/folders/15/ybtbgzpj7636vv4wp92l2c700000gn/T/build859463475789359941.tmp/core.a(Print.cpp.o):(.rodata._ZTI5Print[typeinfo for Print]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
/Users/igrokhotkov/projects/esp8266/arduino/build/macosx/work/Arduino.app/Contents/Resources/Java/hardware/tools/esp8266/xtensa-lx106-elf/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/lib/libc.a(lib_a-abort.o):(.literal+0x0): undefined reference to `_exit'
/Users/igrokhotkov/projects/esp8266/arduino/build/macosx/work/Arduino.app/Contents/Resources/Java/hardware/tools/esp8266/xtensa-lx106-elf/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/lib/libc.a(lib_a-abort.o): In function `abort':
abort.c:(.text+0x13): undefined reference to `_exit'
/Users/igrokhotkov/projects/esp8266/arduino/build/macosx/work/Arduino.app/Contents/Resources/Java/hardware/tools/esp8266/xtensa-lx106-elf/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/lib/libc.a(lib_a-signal.o):(.literal+0x0): undefined reference to `_getpid_r'
/Users/igrokhotkov/projects/esp8266/arduino/build/macosx/work/Arduino.app/Contents/Resources/Java/hardware/tools/esp8266/xtensa-lx106-elf/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/lib/libc.a(lib_a-signal.o):(.literal+0x4): undefined reference to `_kill_r'
/Users/igrokhotkov/projects/esp8266/arduino/build/macosx/work/Arduino.app/Contents/Resources/Java/hardware/tools/esp8266/xtensa-lx106-elf/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/lib/libc.a(lib_a-signal.o): In function `_raise_r':
signal.c:(.text+0x114): undefined reference to `_getpid_r'
signal.c:(.text+0x122): undefined reference to `_kill_r'
/Users/igrokhotkov/projects/esp8266/arduino/build/macosx/work/Arduino.app/Contents/Resources/Java/hardware/tools/esp8266/xtensa-lx106-elf/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/lib/libc.a(lib_a-mallocr.o):(.literal+0x1c): undefined reference to `_sbrk_r'
/Users/igrokhotkov/projects/esp8266/arduino/build/macosx/work/Arduino.app/Contents/Resources/Java/hardware/tools/esp8266/xtensa-lx106-elf/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/lib/libc.a(lib_a-mallocr.o): In function `malloc_extend_top':
mallocr.c:(.text+0x5e): undefined reference to `_sbrk_r'
mallocr.c:(.text+0x127): undefined reference to `_sbrk_r'
/Users/igrokhotkov/projects/esp8266/arduino/build/macosx/work/Arduino.app/Contents/Resources/Java/hardware/tools/esp8266/xtensa-lx106-elf/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/lib/libc.a(lib_a-freer.o): In function `_malloc_trim_r':
mallocr.c:(.text+0x366): undefined reference to `_sbrk_r'
mallocr.c:(.text+0x38f): undefined reference to `_sbrk_r'
/Users/igrokhotkov/projects/esp8266/arduino/build/macosx/work/Arduino.app/Contents/Resources/Java/hardware/tools/esp8266/xtensa-lx106-elf/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/lib/libc.a(lib_a-freer.o):mallocr.c:(.text+0x3a0): more undefined references to `_sbrk_r' follow
collect2: error: ld returned 1 exit status


I'm sure all the sbrk, getpid, kill, etc can be replaced with stubs (I'll do that), but what about "undefined reference to vtable for __cxxabiv1::__si_class_type_info"?
User avatar
By jcmvbkbc
#3004
igrr wrote:
Code: Select all/var/folders/15/ybtbgzpj7636vv4wp92l2c700000gn/T/build859463475789359941.tmp/core.a(HardwareSerial.cpp.o):(.rodata._ZTI6Stream[typeinfo for Stream]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
/var/folders/15/ybtbgzpj7636vv4wp92l2c700000gn/T/build859463475789359941.tmp/core.a(HardwareSerial.cpp.o):(.rodata._ZTI14HardwareSerial[typeinfo for HardwareSerial]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
/var/folders/15/ybtbgzpj7636vv4wp92l2c700000gn/T/build859463475789359941.tmp/core.a(Print.cpp.o):(.rodata._ZTI5Print[typeinfo for Print]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'


I'm sure all the sbrk, getpid, kill, etc can be replaced with stubs (I'll do that), but what about "undefined reference to vtable for __cxxabiv1::__si_class_type_info"?

Looks like it needs to be compiled with -fno-rtti. Can you share the code and build commands?