究竟如何“制造一切"?作品? [英] How exactly "make all" works?

查看:62
本文介绍了究竟如何“制造一切"?作品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在研究makefile的用法.假设我有很多函数 fun_i.c ,其中我在[1,100]中.我将它们全部写在单独的.c文件中,以便在我仅更改其中一些文件时可以更快地进行编译.我需要创建一个Makefile.我在想这样的事情:

So I am studying makefiles usage. Let's say I 've many functions fun_i.c where i is in [1,100]. I have wrote them all in seperate .c files in order to make faster compilation when I only change some of them. I need to create a Makefile. I was thinking something like that:

all : program
program: fun1.o fun2.o   ........ fun100.o main.o
         gcc -o program fun1.o fun2.o ..... fun100.o
fun1.o: fun1.c
        gcc -c fun1.c 
.
.
.
fun100.o: fun100.c 
          gcc -c fun100.c
main.o : main.c 
         gcc -c main.c 

我在网上阅读了很多关于目标所有"如何实现的文章.确保每次我在函数中进行更改时,调用make都只会更新更改内容(因此,我将避免不必要的重新编译).但是,我不确定我是否在这里使用它.我检查了我的makefile文件(虽然有两个功能),但工作正常.但是我不确定这是否是在这里利用全部 all 的方式.我试图将其删除,只在下面保留 program 和下面的代码即可.我想念什么?您能否提供所有至关重要的示例?

I 've read many articles online talking about how the target "all" makes sure that everytime I change something in a function and I call make it will update only what changes (so I'm going to avoid uneccessary recompilation). However, I am not sure if I am using it right here. I checked my makefile ( with 2 functions though) and it worked fine. But I am not sure if that's the way to take advantage of all here. I tried to remove it and just leave program and below.. there and it worked as fine. What am I missing? Could you may provide examples that all is critical?

推荐答案

我在网上阅读了许多文章,谈论目标如何全部"实现.确保每次我更改函数中的某些内容时,我都会调用使其仅更新所做的更改

I 've read many articles online talking about how the target "all" makes sure that everytime I change something in a function and I call make it will update only what changes

all 毫无意义.这只是一个约定.您必须正确定义目标才能执行所需的操作.如果您想全部制作来重新编译所有内容,则需要对其进行定义以使其能够执行此操作.

all does not mean anything. It's just a convention. You have to define the targets correctly to do what you want. If you want make all to recompile everything, you need to define it so that it does that.

所以我将避免不必要的重新编译

so I'm going to avoid uneccessary recompilation

在实践中,我会说这是一个完全不必要的问题,并且创建执行此操作的makefile是浪费时间.如果您的项目很大,则不应手动创建makefile.您使用了像cmake这样的构建系统.

In practice, I'd say that this is a completely unnecessary concern, and it's a waste of time creating makefiles that does this. If you have a large project you should not create makefiles manually. You use a build system like cmake.

如果项目很小并且仅包含几个文件,则通常编译时间不是问题.对于一个小型项目,我使用makefile的目标是不必一直输入编译器标志.

If the project is small and only contain a few files, then the compilation time is in general not an issue. For a small project, my goal with a makefile would be to not have to type the compiler flags all the time.

以下是一个makefile文件,该文件对于大多数非常小的项目(如学校作业)都可以正常工作

Here is a makefile that would work fine for most very small projects like school assignments:

CFLAGS=-Wall -Wextra -pedantic -std=c17 -fsanitize=address
LIBS=-lm -lpthread

program:
        gcc $(CFLAGS) $(LIBS) *.c

clean:
        rm -rf *.o *~

这篇关于究竟如何“制造一切"?作品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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