简体   繁体   English

为什么我在 makefile 中指定的编译器标志没有出现在我的终端(Cygwin)output 中?

[英]Why aren't compiler flags I specify in my makefile showing up in my terminal (Cygwin) output?

So I'm trying to run C code with a Cygwin terminal and I have a makefile called Makefile.mak with the following in it:所以我正在尝试使用 Cygwin 终端运行 C 代码,我有一个名为 Makefile.mak 的 makefile,其中包含以下内容:

CFLAGS=-Wall -g

clean:
    rm -f ex3
    

The book I have "Learn C the Hard Way" says I need to use the command "make clean", however, when I write this I get the error我的书“Learn C the Hard Way”说我需要使用命令“make clean”,但是,当我写这个时,我得到了错误

make: *** No rule to make target 'clean'.  Stop.

It only works if I type仅当我键入时才有效

make -f Makefile.mak clean."

The next problem is that when I try the make command on my C file (ex3.c) I get the output下一个问题是,当我在 C 文件(ex3.c)上尝试 make 命令时,我得到 output

cc     ex3.c   -o ex3

yet I am supposed to see the flags in that output from my makefile as well.但是我也应该从我的 makefile 中看到 output 中的标志。 Like this:像这样:

cc -Wall -g   ex3.c   -o ex3.

I've tried changing the settings in my gcc compiler and still nothing.我尝试更改 gcc 编译器中的设置,但仍然没有。

I also have the makefile and my C code file in the same file path.我在同一文件路径中还有 makefile 和我的 C 代码文件。

Any help would be greatly appreciated.任何帮助将不胜感激。

The filename Makefile.mak is not picked up by make by default.文件名 Makefile.mak 默认不被make拾取。 You need to name it either "makefile" or "Makefile" for that.为此,您需要将其命名为“makefile”或“Makefile”。

As for the compile command, you didn't specify a target on how to build ex3.至于编译命令,您没有指定如何构建 ex3 的目标。 You need to add that:您需要添加:

ex3: ex3.c
    cc $(CFLAGS) -o $@ $^

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的程序没有显示任何 output? 0 个错误,0 个警告但没有 output? 我正在使用 Dev C++ 编译器 - Why is my program not showing any output? 0 errors, 0 warnings but no output? I'm using Dev C++ compiler 为什么我的矩阵不加? - Why aren't my matrices adding? 为什么我的进程并不同时运行? - Why aren't my processes running concurrently? 为什么我的代码块上没有显示输出? - Why there is no output showing on my codeblocks? 为什么我在ideone和codechef编译器中而不是在我的终端中遇到运行时错误? - Why i'm getting runtime error in ideone and codechef compiler and not in my terminal? 为什么在程序退出之前我的输出不显示? - Why doesn't my output show up until the program exits? 为什么我的输出显示两倍于我输入的限制? - Why is my output showing twice the limit I have entered? cygwin无法从/ cygdrive找到我的编译器 - cygwin cannot find my compiler from /cygdrive 为什么不保存我的变量? 我一直在测试此代码,但我的变量未保存到结构数组中 - Why aren't my variables being saved? I've been testing this code and my variables aren't being saved into my struct array cygwin终端将我的字母转换为数字 - cygwin terminal converts my letters to numbers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM