• 嵌套Makefile问题解决一例


    先看一下目录结构

     

    image

    总控Makefile如下:

       1:  CFLAGS=-Wall
       2:  CC=gcc
       3:   
       4:   
       5:  SUBDIRS=server client
       6:   
       7:  export CFLAGS CC
       8:   
       9:   
      10:   
      11:  all:$(SUBDIRS)
      12:   
      13:  $(SUBDIRS):
      14:      make -C $@
      15:   
      16:   
      17:  clean:
      18:      $(RM) server/*.o  server/server 
      19:      $(RM) client/*.o client/client
      20:  .PHONY:clean 

     

    另外两个Makefile分别如下:

       1:  server:server.o
       2:      $(CC) $(CFLAGS) $^ -o $@
       3:   
       4:  server.o:server.c
       5:      $(CC) $(CFLAGS) -c $^ -o $@

       1:  client:client.o
       2:      $(CC) $(CFLAGS) $^ -o $@
       3:   
       4:  client.o:client.c
       5:      $(CC) $(CFLAGS) -c $^ -o $@

     

    当执行总控Makefile时,出现如下现象:

    image 

    无法实现程序的编译。

     

    解决方法:

    方法一、将总控Makefile中的$(SUBDIRS)中的两个路径都声明为 伪目标。

     

       1:  CFLAGS=-Wall
       2:  CC=gcc
       3:   
       4:   
       5:  SUBDIRS=server client
       6:   
       7:  export CFLAGS CC
       8:   
       9:   
      10:   
      11:  all:$(SUBDIRS)
      12:   
      13:  $(SUBDIRS):
      14:      make -C $@
      15:   
      16:   
      17:  clean:
      18:      $(RM) server/*.o  server/server 
      19:      $(RM) client/*.o client/client
      20:  .PHONY:clean server client 

     

    再次指向make

    image

    方法二、将总控Makefile作如下修改

     

       1:  CFLAGS=-Wall
       2:  CC=gcc
       3:   
       4:   
       5:  SUBDIRS=server client
       6:   
       7:  export CFLAGS CC
       8:   
       9:   
      10:   
      11:  all:$(SUBDIRS)
      12:   
      13:  $(SUBDIRS):pp
      14:      make -C $@
      15:  pp:
      16:   
      17:  clean:
      18:      $(RM) server/*.o  server/server 
      19:      $(RM) client/*.o client/client
      20:  .PHONY:clean

     

    image

  • 相关阅读:
    git修改远程仓库地址
    Result Maps collection already contains value for com.miniprogram.meirong.user.dao.UserMapper.BaseResultMap
    查看微信小程序的appID和secret
    Springboot配置fastjson开发
    本地仓库上传码云
    总结分析Java常见的四种引用
    equals和hashcode 和 ==方法说明
    关于Class.forName(className).newInstance()介绍
    Java枚举
    抽象工厂模式-与-工厂方法模式区别
  • 原文地址:https://www.cnblogs.com/pengdonglin137/p/2960210.html
Copyright © 2020-2023  润新知