Makefile to compile multiple C programs?

前端 未结 8 1179
予麋鹿
予麋鹿 2020-12-02 09:41

This is an incredibly simple question, but I\'m new to makefiles. I am trying to make a makefile that will compile two independent programs:

program1:
    gc         


        
8条回答
  •  时光说笑
    2020-12-02 10:26

    A simple program's compilation workflow is simple, I can draw it as a small graph: source -> [compilation] -> object [linking] -> executable. There are files (source, object, executable) in this graph, and rules (make's terminology). That graph is definied in the Makefile.

    When you launch make, it reads Makefile, and checks for changed files. If there's any, it triggers the rule, which depends on it. The rule may produce/update further files, which may trigger other rules and so on. If you create a good makefile, only the necessary rules (compiler/link commands) will run, which stands "to next" from the modified file in the dependency path.

    Pick an example Makefile, read the manual for syntax (anyway, it's clear for first sight, w/o manual), and draw the graph. You have to understand compiler options in order to find out the names of the result files.

    The make graph should be as complex just as you want. You can even do infinite loops (don't do)! You can tell make, which rule is your target, so only the left-standing files will be used as triggers.

    Again: draw the graph!.

提交回复
热议问题