macos - Mac OS X : no target found 上的 Makefile 问题

标签 macos makefile

我正在 OS X 上编写 makefile,但遇到了问题。我做了我应该做的一切(我认为),但只有一部分在工作。当我尝试时:

make file1

或:

make file2

一切似乎都很好,但当我尝试时:

make all

或:

make clean

我得到了典型的:

*** No rule to make target

这是代码,希望你能发现问题:

CC = gcc
CFLAGS=-Wall
FILES=file1 file2

all: $(FILES)

file1: file1.c
    $(CC) $(CFLAGS) file1.c -o file1

file2: file2.c
    $(CC) $(CFLAGS) file2.c -o file2

clean: 
    $(RM) $(FILES)

干杯!

最佳答案

将评论转化为答案,主要是为了关闭问题。

没有明显的理由说明所显示的语法会导致该问题,所以我怀疑 make file1 在没有任何 makefile 的情况下工作,并提出了一个默认规则来进行编译(并且可能不会'编译时不要使用 -Wall 选项。

您创建的 makefile 的名称是什么?

The makefile is named makefile, and you are indeed right: -Wall isn't used (I just noticed).

这很好奇。仔细看名字:ls m* | od -c。查看这些字母是否符合您的预期,名称末尾没有尾随空格或类似的任何不良内容。

但是“no -Wall”的观察实际上证实了问题出在 makefile 的名称上,尽管它为什么不起作用还不明显.您可以尝试 make -f makefile all 看看是否有任何不同。如果名称错误,您应该会被告知它无法打开 makefile

I tried remaking a makefile from scratch containing exactly the same information and it runs smoothly. You were definitely right about the name issue.

这类问题既奇怪又令人困惑——寻求帮助是明智的。

关于macos - Mac OS X : no target found 上的 Makefile 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34362808/

相关文章:

objective-c - 如何查看哪些对象保留了另一个特定对象

objective-c - 使用结构清理绑定(bind)

c++ - 如何在Makefile中对两组文件使用不同的规则?

c - 如何扩展makefile来编写库?

macos - 在 Mac 上安装 "perf"

macos - 在 Mac (Lion) 上安装 Apache : "Did not find prce-config script at" error

macos - "Vault"、"Consul"和 "Terraform"[Hashicorp 产品] 无法打开,因为在 mac、Catalina 上无法验证开发者问题

c++ - Makefile 编译 c 和 cpp 文件

c - 制作 : Totally ignoring a rule

bash - 语法错误 : end of file unexpected (expecting "fi")