基本的Makefile和标头依赖项 [英] Basic Makefile and header dependencies

查看:102
本文介绍了基本的Makefile和标头依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是makefile的新手,但我有点卡住.我有两个名为trade.c和report.c的c源文件.它们都依赖于一个名为acc.h的文件. acc.h文件由其他两个头文件,users.h和resellers.h组成.我想知道如何将两个头文件的依赖项写入acc.h文件.我到目前为止...

I am new to makefiles and I am a bit stuck. I have two c source files called trade.c and report.c . They both depend on a file called acc.h. The acc.h file is composed of two other header files, users.h and resellers.h. I am wondering how you write the dependency of the two header files to the acc.h file. I have so far...

OBJECTS = trade.c report.c
CC = gcc

trading: $(OBJECTS)
        $(CC) $(OBJECTS) -o trading

trade.o: trade.c accts.h
        $(CC) -c trade.c

report.o: report.c accts.h
        $(CC) -c report.c

任何帮助将不胜感激.

Any help is greatly appreciated.

推荐答案

除了将所有头文件添加到目标文件的依赖项列表中之外,您别无选择,如下所示.

You have no other choice than to add all the header files in the dependency list for the object file, as follows.

trade.o: trade.c accts.h users.h resellers.h
        $(CC) -c trade.c

这篇关于基本的Makefile和标头依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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