Run Executable from makefile

前端 未结 1 1883
误落风尘
误落风尘 2021-02-19 02:25

Hey I just have a quick question about makefile\'s. Is there some way to auto run the executable generated from a makefile?

Like if I just type \"make\" it will compile

相关标签:
1条回答
  • 2021-02-19 02:52

    If you run make without specifying any targets, it would execute the first target it finds within the Makefile. By convention all is the name of such a target.

    If you make run a pre-requisite for all and mark both all and run as PHONY targets, you should be good to go.

    all: run
    
    run: prog1
        ./prog1
    
    .PHONY: all run
    

    BTW, I presume you already have some rules for building prog1 in your Makefile, and hence have not included it in the above shown Makefile.

    An alternative would be to just invoke make explicitly with the run target, i.e. execute the following command:

    make run
    
    0 讨论(0)
提交回复
热议问题