从具有多个代码目录的Makefile中调用subdir.mk [英] Calling subdir.mk from Makefile with multiple code directories

查看:66
本文介绍了从具有多个代码目录的Makefile中调用subdir.mk的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的代码的文件夹结构.这是一个非常小的示例,可以理解多个makefile的概念,在此基础上,我必须为更大的代码结构创建makefile.

Below is the folder structure for my code. This is a very small example to understand the concept of multiple makefiles based on which I have to create makefile for bigger code structure.

work
├── code
|     | 
|     └── main.h and test.h files here
│     └── main.c and test.c files here
|     └── subdir.mk
|
├── _Build/
│     └── Makefile here

我将Makefile和subdir.mk文件都保持为非常基本且易于理解的概念.

I am keeping both Makefile and subdir.mk files to be very basic and simple to grasp the concept.

下面是subdir.mk的代码

Below is the code for subdir.mk

#subdir.mk
#============================================
test.o : test.c test.h
    @echo Building test.c ...
    gcc -Werror -Wall -c test.c -o test.o

main.o : main.c main.h test.h
    @echo Building main.c ...
    gcc -Werror -Wall -c main.c -o main.o
#============================================

下面是主文件... Makefile的代码

Below is the code for main file ... Makefile

#Makefile
#============================================

include ../code/subdir.mk

main : ../code/main.o ..code/test.o
    @echo Building ...

    make subdir.mk # <--- What is the correct way to perform this code

    @echo Linking files ...
    gcc -Llib ../code/main.o ../code/test.o -lm -o main

clean:
    rm -rv ../code/*.o
#============================================

我得到的错误是

make: *** No rule to make target 'test.c', needed by 'test.o'.  Stop.

在subdir.mk中,我试图生成目标文件.在Makefile中,我试图链接在subdir.mk中生成的目标文件

In subdir.mk I am trying to generate object files. In Makefile I am trying to link the object files generated in subdir.mk

我尝试执行的方法是正确的方法,或者当我们有多个subdir.mk和主Makefile时,遵循了一些不同的步骤.

The way I am trying to execute is correct way or some different steps are followed when we have multiple subdir.mk and main Makefile.

请分享您的宝贵意见.

推荐答案

subdir.mk 必须使用相对于主Makefile的路径.例如

subdir.mk has to use paths relative to the main makefile. E.g.

../code/test.o : ../code/test.c ../code/test.h
   ...

这篇关于从具有多个代码目录的Makefile中调用subdir.mk的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆