How to define C++ preprocessor variable in Makefile

前端 未结 5 1174
Happy的楠姐
Happy的楠姐 2020-12-13 17:22

I have a C++ preprocessor written like this:

  #ifdef cpp_variable
   //x+y;
  #endif

Can anyone tell me how to define this in Makefile.

相关标签:
5条回答
  • 2020-12-13 17:48

    Take a variable in Makefile and whatever you need to define in it just add -DXXX. Where XXX in you case is cpp_variable.

    For example

    COMPILE_OPTS = -DXXX

    g++ -c $(COMPILE_OPTS) $<

    0 讨论(0)
  • 2020-12-13 18:05

    The syntax is compiler specific, for gcc use the -D option like so: -Dcpp_variable.

    0 讨论(0)
  • 2020-12-13 18:10

    Search your compiler documentation to find how to do that.

    For example for g++ the syntax is :

    g++ -Dcpp_variable <other stuff>
    

    Which corresponds to adding

    CPPFLAGS += -Dcpp_variable
    

    in your makefile.

    0 讨论(0)
  • 2020-12-13 18:14

    This is compiler specific.

    GCC uses -Dcpp_variable=VALUE or just -Dcpp_variable

    Microsoft's compilers use /D

    0 讨论(0)
  • 2020-12-13 18:14

    Add to Makefile:

    CPPFLAGS = -Dcpp_variable
    
    0 讨论(0)
提交回复
热议问题