c++ projects in IDF?

jimcondit
Posts: 4
Joined: Fri Nov 19, 2021 2:18 am

c++ projects in IDF?

Postby jimcondit » Sun Dec 05, 2021 3:15 am

Is there an easy way to create a new cpp project in the idf? I'm trying to migrate a sketch from Android IDE, which is generally working there, to IDF. I can see some reference to using the naming convention "main/main.cpp" and changes to the make files, but I can't make it work. Any documentation?

silardgal_dotlab
Posts: 4
Joined: Fri Nov 26, 2021 12:50 pm

Re: c++ projects in IDF?

Postby silardgal_dotlab » Mon Dec 06, 2021 3:25 pm

Just use

Code: Select all

extern "C" void app_main()
and rename your main.c to main.cpp :D

StuartLittle57
Posts: 4
Joined: Mon Dec 06, 2021 4:09 pm

Re: c++ projects in IDF?

Postby StuartLittle57 » Mon Dec 06, 2021 4:24 pm

app_main() is called by C code. If you compile your main file as cpp this function name will be mangled. The solution is to define app_main as extern "C" so it can be called from C. That's all. We use C++ in all our projects.

Code: Select all

extern "C" void app_main(void)
{
}
Just note that exceptions are disabled by default. You can enable them in menuconfig.
Also if you want to use modern C++ features you can set C++ version to C++17 in CMakeLists.txt:

Code: Select all

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

Who is online

Users browsing this forum: Bing [Bot], FX2032 and 121 guests