1
/* Example.h */

#define QUOTE(str)                      #str
#define EXPAND_AND_QUOTE(str)           QUOTE(str)

#define HOUSTON_INCLUDE_PATH            u:/PlatformPkgs/HoustonPkg/Include
#define HOUSTON1_INCLUDE_PATH           u:/PlatformPkgs/Houston1Pkg/Include

// HOUSTON1 is defined in CFLAGS with /DHOUSTON1
#if defined(HOUSTON)   
#include EXPAND_AND_QUOTE(HOUSTON_INCLUDE_PATH/Optional.h)
#elif defined (HOUSTON1)
#include EXPAND_AND_QUOTE(HOUSTON1_INCLUDE_PATH/Optional.h)
#endif

Got the compiling error below:

C1083: Cannot open include file: 'u:/PlatformPkgs/1/Include/Optional.h': No such file or directory

The error is due to the macro is expanded tou:/PlatformPkgs/1/Include/Optional.h. It stripped out Houston and Pkg in Houston1Pkg. How can I retain the whole word Houston1Pkg in the path?

Hung Ho
  • 11
  • 2
  • 1
    It doesn't happen with `gcc` I suppose you are using `MSVC`? – Iharob Al Asimi Jan 14 '15 at 23:00
  • Yep, just tested with gcc, cannot reproduce –  Jan 14 '15 at 23:02
  • 8
    Is `Houston1Pkg` defined as `#define Houston1Pkg 1` somewhere? – R Sahu Jan 14 '15 at 23:04
  • See http://stackoverflow.com/questions/12562807/include-absolute-path-syntax-in-c-c – Valeri Atamaniouk Jan 14 '15 at 23:16
  • I use MSVC. Houston1Pkg is the folder name. – Hung Ho Jan 15 '15 at 00:39
  • 2
    You normally specify the location of the headers via a compiler command line option; on Unix, `-Iu:/PlatformPkgs/Houston1Pkg/Include`, and `/I:\PlatformPkgs\Houston1Pkg\Include` with MSVC, I believe. – Jonathan Leffler Jan 15 '15 at 00:55
  • I edit the original post. I understand to specify the location of the header via compiler flag. This issue is different, the optional.h file is reside in two different folders (Houston and Houston1) and the content of optional.h is different between these two folders. – Hung Ho Jan 15 '15 at 01:31
  • @JonathanLeffler: I agree that this question is not particularly related to the suggested duplicate, which has to do with backslashes in the filepath. This question shows an apparently vanishing path segment, which is not related. (I also think RSahu asked the right question; it needs a reply.) Voting to reopen. – rici Jan 15 '15 at 04:03
  • @rici: I don't agree with the reopen, but I'll let the processes take their due course. If that's not the answer, then the probable answer to the plain question is almost certainly `#undef Houston1Pkg` before the block of lines with the `#include` in the shown code. In other words, I expect `Houston1Pkg` is defined as `1` somewhere in the system, either on the command line or in a header (or, perhaps, in the other code before this in the source code). – Jonathan Leffler Jan 15 '15 at 04:22
  • @JonathanLeffler: I do, too, which is why I think RSahu asked the right question. Indeed, the answer you suggest is likely correct, but it cannot be provided as an answer because the question is closed. Not that it matters much -- it's pretty localized. Although I think I remember a question which asks, roughly, "how can I write a macro which will stringify its argument without macro expanding the argument first?" – rici Jan 15 '15 at 04:54
  • 1
    @HungHo: There's no problem. When you need to pick the Houston1Pkg header, you specify that as the path and simple write `#include ` in the code. When you need to pick the HoustonPkg header, you specify that as the path on the command line. So, the path chosen is specified on the command line. All else apart, many machines don't have a `U:` drive. I can simulate it on Unix as a relative pathname, of course. – Jonathan Leffler Jan 15 '15 at 04:54
  • #undef Houston1Pkg fixed the problem. Thanks everyone for the help – Hung Ho Jan 15 '15 at 15:46

0 Answers0