Override macro from the command line

后端 未结 3 1566
猫巷女王i
猫巷女王i 2021-01-04 12:50

I would like to override a macro from the command line. Somewhere in my source, there is a definition like this:

#define MY_FOO 1

What I wo

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-04 13:40

    If the file config.h prevents multiple inclusions (via #ifndef CONFIG_H etc), then you could abuse that:

    g++ -DMY_FOO=2 -DCONFIG_H
    

    Note: If the file config.h contains anything else that you need, then you have to define that yourself again as well. You could make a copy of the file as my_config.h and include that. (See also the -include file preprocessor option).

提交回复
热议问题