Using GCC under Windows, I would like to be able to specify on the gcc command line (or from a manually managed makefile) the name of a specific include file to be included in the file being compiled. As I see it, ideally the source code file would contain a line something like…</p>
#include INCLUDEFILENAME
…then a filename specified on the gcc command line would be substituted for the INCLUDEFILENAME
text.
It seems I can get close to achieving this by defining a macro called INCLUDEFILENAME on the gcc command line using the -D
option (eg. -D INCLUDEFILENAME="C:\TestLib\Test1.h"
) but when the filename text gets substituted into the #include
statement it is not enclosed in double quotes, and without these it is not recognized as a file to be included. Of course…</p>
#include "INCLUDEFILENAME"
…doesn’t work as INCLUDEFILENAME then becomes a string literal and does not get replaced by the macro value. I have tried other ways of specifying the double quotes (\x22
, \"
, "\""
, etc) but these don’t seem to work on the #include
line.
I am aware of the gcc -include
option which it seems can force a file to be included without it being mentioned in any way in the source file, but I would prefer that the source file indicates that an include file is to be included here but that it’s name is specified “externally” to the source file (ultimately, from the makefile).
Any suggestions on how I can achieve this would be appreciated.