- Thu Nov 13, 2014 12:21 pm
#2560
Hi,
I'm trying to compile a c++ application for the ESP8266. I've set up g++ through 'git clone -b lx106-g++' as explained above.
It's mostly working, except for the fact that constructors of global objects are not being called. For example:
Code: Select allclass TestClass
{
public:
TestClass()
: m_a(5) {}
int m_a;
};
TestClass tc;
extern "C" void user_init(void)
{
// if I print tc.m_a here, it will show 0 instead of 5.
}
These are my compiler and linker options:
Code: Select all"/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++" -Wl,-EL -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH -fmessage-length=0 -fverbose-asm -ffunction-sections -fdata-sections -Iinclude -I../../esp8266/esp_iot_sdk_V0.9.2/include/ -I../../cppcomponents/ -Wall -Wundef -Wno-unused-local-typedefs -Wextra -Wno-unused-parameter -Wno-unused-variable -Wno-unused-but-set-variable -Werror=return-type -Wpointer-arith -D_NDEBUG -O3 --std=c++11 -ftree-ter -Wno-reorder -fno-rtti -fno-exceptions -fno-unwind-tables -fno-threadsafe-statics -fno-stack-protector -c -o build/obj/main.o user/main.cpp
AR build/test1_app.a
LD build/test1.out1
"/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc" -L../../esp8266/esp_iot_sdk_V0.9.2/lib -L ../../esp8266/esp_iot_sdk_V0.9.2/ld/ -Teagle.app.v6.ld -Wl,--no-check-sections -u call_user_start -Wl,-static -nostdlib -Xlinker -Map=build/test1.map -Wl,--gc-sections -Wl,--start-group -lc -lgcc -lhal -lphy -lnet80211 -llwip -lwpa -lmain -lupgrade build/test1_app.a -Wl,--end-group -o build/test1.out1
If I omit -nostdlib and use -nodefaultlibs, the linker complains about crt1-sim.o and _vectors.o missing.
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.
Thanks!