Below is my c code:


main() {    
    #ifdef HELLO
        printf(" hello ");
        printf(" else ");

And my Makefiles is:

        gcc uss_main.c -o out

Here I am trying to print hello by executing the binary out. I want to define the macro HELLO only at the time of doing make. I have tried using make HELLO=11but it only printing the else part, I am pretty new to make. Please help me to enhance my Makefile. Thanks in advance.


You can define macro by using GCC compiler flag like this:

gcc -DHELLO=1 uss_main.c -o out

If you want to pass it to make, you need to modify Makefile. Something like this:


     gcc $(USE_HELLO) uss_main.c -o out

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.