This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Please help me passing a path to preprocessor


Hi jp,

If you are using MYPATH as a string in your source code, you may want to put double-quotes around it in the define in the makefile.

-DMYPATH='"/usr/local/thepath"'

Note that the single-quotes are chomped by the shell that the make spawns to launch the compiler.

Another solution is to string-ize the MYPATH macro variable in your code via:

#define STR_2(x) #x
#define STR(x) STR_2(x)

STR(MYPATH)

The helper macro function STR_2 is necessary so the STR x parm gets expanded.  Otherwise you'd end up with "MYPATH" instead of the expansion of MYPATH into /usr/local/thepath that you are hoping for, which STR_2 then stringifies.

You may want to do this instead for STR_2...

#define STR_2(x) L ## #x

...if you need to work with wchar_t strings instead.

HTH,
--Eljay



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]