Search code examples
c++ceclipsebuild-error

Strange Eclipse C++ #define behaviour


(A case of over relying on an IDE)

I have some legacy C code that I compile as C++ for the purpose of Unit testing. The C source is C++ aware in that it conditionally defines based on environment.

E.g. (PRIVATE resolves to static):

#if!defined __cplusplus
#define PRIVATE1 PRIVATE
#endif

...

PRIVATE1 const int some_var;

The problem is I just can't seem to find out what PRIVATE1 resolves to or is in C++, the compiler complains of redefinition if I add a declaration but doesn't indicate where?

I have searched my MinGW/gcc include path, the C++ ISO specification and the C++ books available to me has been to no avail.

Edit:

Sure I checked the command line and makefiles before posting.


Solution

  • Eclipse C++ managed project's are a little, well stupid!

    If a project is declared C++ it still bases it's build on file extension, hence .h file preprocessed as C and not C++ header which pulls in a #define PRIVATE1 from another header file similarly wrapped by:

    #ifdef __cpluplus.
    

    The project is then linked by g++.