Construct path for #include directive with macro

后端 未结 4 849
耶瑟儿~
耶瑟儿~ 2020-11-27 07:54

I would like to have include file paths dynamically created by a macro for a target-configuration-dependent part of my program.

for example, I would like to construc

4条回答
  •  南方客
    南方客 (楼主)
    2020-11-27 08:05

    I would like to have include file paths dynamically created by a macro for a target-configuration-dependent part of my program.

    You should be unable to (and if you are able to do so, you probably shouldn't do this).

    You are effectively trying to do the compiler's job in a source file, which does not make much sense. If you want to change include paths based on the machine you compile on, this is a solved problem (but not solved in a header file).

    Canonical solution:

    Use an IF in your Makefile or CMakeLists.txt, use custom property pages depending on the build configuration in Visual Studio (or simply set the particular settings for your build in the OS environment for your user).

    Then, write the include directive as:

    #include  // no path here
    

    and rely on the environment/build system to make the path available when the compiler is invoked.

提交回复
热议问题