设置我的makefile以仅使用"make"命令编译C. [英] Set up my makefile to compile C with just "make"

查看:69
本文介绍了设置我的makefile以仅使用"make"命令编译C.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做Zed Shaw的学习C的艰难方法"课程,在第2课中,我发现在视频和书籍中,作者仅使用 make ex1 来编译他的C,而我需要运行 gcc -Wall -g ex1.c -o ex1 .这是我的Makefile,似乎第一部分应该是使make命令可以编译的内容,但是"make"命令不能编译它.

I'm doing the Learn C The Hard Way course by Zed Shaw, and on Lesson 2 I find that in the videos and book, the author only uses make ex1 to compile his C, while I need to run gcc -Wall -g ex1.c -o ex1. Here is my Makefile, It seems like the first part is what is supposed to make the make command work to compile, but the "make" command doesn't compile it.

CFLAGs=-Wall -g

clean:
    rm -f ex1.exe

all:
    gcc -Wall -g ex1.c -o ex1.exe




推荐答案

默认目标是第一个目标,因此请切换这些目标的顺序,以使 all 为默认目标.

The default goal is the first goal, so switch the order of these so that all is the default.

有关目标的文档中有更多详细信息:

默认情况下,目标是makefile中的第一个目标(不计算以句点开头的目标).因此,通常编写makefile,以便第一个目标是编译它们描述的一个或多个程序.如果makefile中的第一个规则具有多个目标,则仅该规则中的第一个目标成为默认目标,而不是整个列表.您可以使用 .DEFAULT_GOAL 变量从makefile中管理默认目标的选择
By default, the goal is the first target in the makefile (not counting targets that start with a period). Therefore, makefiles are usually written so that the first target is for compiling the entire program or programs they describe. If the first rule in the makefile has several targets, only the first target in the rule becomes the default goal, not the whole list. You can manage the selection of the default goal from within your makefile using the .DEFAULT_GOAL variable

这篇关于设置我的makefile以仅使用"make"命令编译C.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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