Page 1 of 1

Xtensa compiler considering the ".h" file as C header file?

Posted: Tue May 21, 2019 9:13 am
by jotman01
HI,

i am working on porting some proj into esp-idf environment where C++ class and namespaces are declared in ".h" file instead of ".hpp",
xtensa-32 compiler throws error saying that could not find "namespace" and could not find "class" error.

i could not see any option to force the compiler to cosider it as C++ header file during compilation.

regards
jotman01

Re: Xtensa compiler considering the ".h" file as C header file?

Posted: Wed May 22, 2019 3:06 am
by ESP_Sprite
The compiler will not try to interpret .h/.hpp files by itself; it will only include it if a .c/.cpp file has an include directive for it. As .c files are compiled with the C compiler and .cpp files are compiled with the C++ compiler, a .h file included in a .c file will also be compiled by the C compiler and will error out. The solution here is to not include any c++-specific structures in headers that are going to be included in plain .c files, and/or converting any .c files that do need to include headers that have C++ structures in them to .cpp files.