Reputation: 1980
In a project, I am using separate header files to specify parameters for separate configurations. For example, config1.h
and config2.h
. I have created separate build configurations in Eclipse for each configuration and added symbol PARAM_H_FILE
assigned either PARAM_H_FILE=config1.h
or PARAM_H_FILE=config2.h
in Eclipse as a defined symbol for the respective build configuration. In order to include this file, I have added the following lines to a common header file in the project:
#define QT(filename) #filename //!< Convert filename to string
#define QUOTE(filename) QT(filename) //!< Expand filename string
// Include header file.
#include QUOTE(PARAM_H_FILE) // Include vehicle definitions
The compiler expands this to #include "config1.h"
or include "config2.h"
as desired and compiles with no errors or warnings. However, the Eclipse CDT indexer expands this to #include "\"config1.h\""
or #include "\"config1.h\""
, resulting in detected errors any time the macros defined in config1.h
or config2.h
are referenced in the code.
Also, I found that if I replace the above code with the following, then Eclipse does not detect any errors, but the project compiles with errors:
#include QUOTE(PARAM_H_FILE) // Include vehicle definitions
Is there any way to specify the header file name as a defined symbol in Eclipse that will prevent the indexer from identifying errors and allow the project to build.
I have tried formatting the symbol definition as: PARAM_H_FILE=config1.h
, PARAM_H_FILE='config1.h'
, PARAM_H_FILE='"config1.h"'
and PARAM_H_FILE="config1.h"
and nothing seems to work.
As a point of reference, I am using is MinGW.org GCC-8.2.0-5 in Windows and Eclipse IDE for C/C++ Developers, Version: 2019-06 (4.12.0).
Upvotes: 0
Views: 54
Reputation: 1980
After investigating further, I found that this was being caused by an "
added before and after the symbol assigned value in the .cproject XML file. This may have been added by an older version of Eclipse. In Eclipse 2019-06 (4.12.0), the quotation mark indicated by "
is not visible in the Project Properties window.
For example, the XML file may read:
<listOptionValue builtIn="false" value=""PARAM_H_FILE=config.h""/>
,
But the Project Properties reads:
VC_PARAM_H_FILE=config.h
instead of VC_PARAM_H_FILE="config.h"
.
The easiest way to remove "
manually from the .cproject XML file.
Upvotes: 0