c - 设置我的 makefile 以仅使用 "make"编译 C

标签 c makefile cmder

我正在学习 Zed Shaw 的 Learn C The Hard Way 类(class),在第 2 课中,我发现在视频和书中,作者只使用 make ex1 来编译他的 C,而我需要运行 gcc -Wall -g ex1.c -o ex1。这是我的 Makefile,看起来第一部分应该是让 make 命令可以编译的,但是“make”命令没有编译它。

CFLAGs=-Wall -g

clean:
    rm -f ex1.exe

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




最佳答案

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

the documentation on goals 中有更多详细信息:

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

关于c - 设置我的 makefile 以仅使用 "make"编译 C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54119488/

相关文章:

c - 将我的 .txt 文件打印到行和列时遇到问题,仅打印第一行

c - 查找图像的方向

c - 根据字符串创建的反转数

c - 在 Linux 中创建静态库时出现问题

c++ - CMake 用户构建的库;无法为目标指定链接库

创建库函数

c++ - 使用 Makefile 在多个文件 C++ 中构建互连类

command-line - 无法在cmder中更改驱动器

visual-studio-code - VSCode + Cmder 集成 - 奇怪的问题