How can I define #define in my Make files

后端 未结 3 1415
借酒劲吻你
借酒劲吻你 2021-02-07 18:02

In my c/c++ files, there are multiple #define. As an example:

#ifdef LIBVNCSERVER_HAVE_LIBZ
  /* some code */
#ifdef LIBVNCSERVER_HAVE_LIBJPEG
  /* some more cod         


        
3条回答
  •  执念已碎
    2021-02-07 18:25

    Add the line below, to your makefile:

    DEFINES=LIBVNCSERVER_HAVE_LIBZ LIBVNCSERVER_HAVE_LIBJPEG
    ...
    ... further on in your makefile on the line where it says ....
    ...
        $(cc) ($(addprefix -D, $(DEFINES))) .....
    ...
    ...
    

    This is to serve as an example, you only add another define to the DEFINES variable which gets referenced on the line as shown $(cc) -D$(DEFINES) in which the make will automatically expand the variable and compile those that are #ifdefd.

    Thanks to R Samuel Klatchko for pointing out a small amiss...this is specifically for GNU's make, you can use addprefix do properly do that ($(addprefix -D, $(DEFINES))).

提交回复
热议问题