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

jotman01
Posts: 2
Joined: Tue May 21, 2019 8:58 am

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

Postby jotman01 » Tue May 21, 2019 9:13 am

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

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

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

Postby ESP_Sprite » Wed May 22, 2019 3:06 am

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.

Who is online

Users browsing this forum: Baidu [Spider] and 132 guests