-->
Page 6 of 7

Re: C++

PostPosted: Sun Jan 18, 2015 3:24 am
by Alex_S
jcmvbkbc, igrr,
Thanks a lot for your recomendations!
Great work!!!

Re: C++

PostPosted: Fri Mar 13, 2015 10:16 pm
by Pawel Ka
Hi (first post ;-))

I'm trying to use g++ (compiler related with this thread) and virtual function, but code crashes on ESP while invoking virtual function.

Sample code:
Code: Select allclass A {
   public:
   void run(){
      foo();
   }
   virtual void foo() = 0;
};

class B : public A{
   public:
   void foo(){
      Serial.println("TEST"); //what ever debug information you need
   }
};

B test;
test.foo(); //works, I see TEST in termial
test.run(); //crashes with Exception(28)


Error message:
Code: Select allFatal exception (28):
epc1=0x4024dfc5
epc2=0x00000000
epc3=0x4024306f
epcvaddr=0x00000000
depc=0x00000000


Does anyone have idea what can be wrong with compiler? The same code with g++ x86 compiler works properly.

Re: C++

PostPosted: Sat Mar 14, 2015 10:01 pm
by Pawel Ka
I found that I had configured g++ parameter "-fno-rtti", so no support for virtual functions (it's main problem), but after removing parameter I have a problem with missing reference to vtable.

Does anyone know, how to use virtual functions (vtable) with esp8266? What kind of parameters should be added to compiler?

Re: C++

PostPosted: Sun Mar 15, 2015 3:44 am
by joostn
-f-no-rtti is fine, I'm using that as well.
Are you running the global constructors manually? This is required because the startup code doesn't do it. See page 1 of this same thread. You can see if this is the case by moving your test code inside a function (void test()) and see if it works, because then it's not a global object anymore.

If you don't, your class B (including virtual function table) will not be initialized.