Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please provide toolchain with c++ RTTI enabled (IDFGH-1180) #3492

Closed
bpietsch opened this issue May 17, 2019 · 3 comments
Closed

Please provide toolchain with c++ RTTI enabled (IDFGH-1180) #3492

bpietsch opened this issue May 17, 2019 · 3 comments

Comments

@bpietsch
Copy link

I would like to request that you please provide a version of the toolchain that has C++ RTTI enabled by default. RTTI is an essential part of most C++ development and having to build a custom toolchain is cumbersome. Thank you!

@github-actions github-actions bot changed the title Please provide toolchain with c++ RTTI enabled Please provide toolchain with c++ RTTI enabled (IDFGH-1180) May 17, 2019
@chanibal
Copy link
Contributor

chanibal commented May 20, 2019

I wouldn't say that RTTI is essential to most of C++ development, nevertheless, ESP-IDF supports it, just configure your compiler.

Create a component.mk file in your main directory and in all components (if you use them) are with the contents:

CPPFLAGS += -frtti

Checked with:

class Person
  {
    public:
       virtual ~Person() {}
  };

 class Employee : public Person
 {
 };

#include <esp_log.h>
#include <typeinfo>
extern "C" void app_main(void) {
   Person person;
   Employee employee;
   Person* ptr = &employee;
   Person& ref = employee;
   // The string returned by typeid::name is implementation-defined
   ESP_LOGI("RTTI", "%s", typeid(person).name());   // Person (statically known at compile-time)
   ESP_LOGI("RTTI", "%s", typeid(employee).name()); // Employee (statically known at compile-time)
   ESP_LOGI("RTTI", "%s", typeid(ptr).name());      // Person* (statically known at compile-time)
   ESP_LOGI("RTTI", "%s", typeid(*ptr).name());     // Employee (looked up dynamically at run-time because it is the dereference of a pointer to a polymorphic class)
   ESP_LOGI("RTTI", "%s", typeid(ref).name());      // Employee (references can also be polymorphic)
}

Results in:

I (49) RTTI: 6Person
I (49) RTTI: 8Employee
I (49) RTTI: P6Person
I (49) RTTI: 8Employee
I (59) RTTI: 8Employee

@bpietsch
Copy link
Author

The compiler supports it, yes, but the standard libraries included in the pre-built toolchain do not.

@igrr
Copy link
Member

igrr commented Jun 5, 2019

Closing this as a duplicate of an older issue, #1684. To receive further updates, please follow the link and click the "Subscribe" button. Thanks.

@igrr igrr closed this as completed Jun 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants