This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How can I use the c++ compiler for .h files?

Hello,

I have a project that is programmed in c++. My header-files end in .hh, as they should. My project is related to another one, programmed in C++, too, but they use .h as suffix for header-files. To be sure, that the c++ compiler is used for all files, I added the '--cpp-default' switch to the compiler options, but I still get this error message:

cppe674 somefile.cpp ...
"anotherfile.h", line 18: error: expected a declaration

The line in question is:

namespace DSP {

so I suspect, that it comes from a c-compiler. What can I do to /really/ default to the c++ compiler?

cu
Markus

  • The --cpp_default switch (note the underscore) does not affect how the compiler interprets header file names.  You can use whatever extension you like.  The compiler uses the extension on the input module (the .c or .cpp file) to determine whether the file is C or C++.  If it does not recognize it as a CPP file, assembly file, etc.  It assumes the input module is C, unless the --cpp_default option is used, in which case it assumes it is C++. 

    I suspect your problem isn't with --cpp_default.  Could you show some more context before the line in question?  When you see "expected a declaration", often this means that there is an error with the code leading up to the error, such as a missing semicolon.  This error might be in the file that includes anotherfile.h

  • You are right, it was a case of pebkac. Only after I used --preproc_only to see what's really going on, I was able to solve the problem. Thanks for your hint!

    cu

    Markus