简体   繁体   English

Makefile中的标志未出现

[英]Cflags in Makefile not appearing

I have a makefile, but it seems like the cflags are only working for certain files in my program, and I am not sure why. 我有一个makefile,但似乎cflags仅对程序中的某些文件有效,我不确定为什么。

Here is what happens when I use make: 这是我使用make时发生的情况:

$ make
gcc -Wall -ansi -pedantic -g -c main.c
gcc  -c fw.c
gcc  -c trie.c
gcc -Wall -ansi -pedantic -g -c linked.c
gcc -Wall -ansi -pedantic -g -o fw main.o fw.o trie.o linked.o

You can see that when trying to make fw.c and trie.c it doesn't include the flags, but it does include the flags for the other files. 您可以看到,尝试制作fw.c和trie.c时,它不包含标志,但确实包含其他文件的标志。

Here is my makefile: 这是我的makefile:

 CC = gcc
 CFLAGS = -Wall -ansi -pedantic -g
 MAIN = main
 OBJS = main.o fw.o trie.o linked.o
 all : $(MAIN)

 $(MAIN) : $(OBJS) fw.h trie.h linked.h
     $(CC) $(CFLAGS) -o fw $(OBJS)

 main.o : main.c fw.h trie.h linked.h
     $(CC) $(CFLAGS) -c main.c

 fw.o : fw.c fw.h trie.h
     $(CC) $(CGLAGS) -c fw.c

 trie.o : trie.c fw.h trie.h linked.h
     $(CC) $(CGLAGS) -c trie.c

 linked.o : linked.c trie.h linked.h
     $(CC) $(CFLAGS) -c linked.c

 rm :
     rm *.o $(MAIN) core

I also have an additional problem in that whenever I use make with unchanged files from the last make, it still executes this line: 我还有一个额外的问题,就是每当我使用make与上一个make中未更改的文件时,它仍然执行以下行:

$ make
gcc -Wall -ansi -pedantic -g -o fw main.o fw.o trie.o linked.o

Whereas usually, it gives me the message "nothing to be done for all". 通常,它给我的信息是“什么都不要做”。 I have tried to compare this makefile to my other working makefiles, but I can't find the error(s). 我试图将此Makefile与其他工作的Makefile进行比较,但找不到错误。 Where have I gone wrong? 我哪里出问题了?

You have typos in your Makefile : 您的Makefile有错别字:

 fw.o : fw.c fw.h trie.h
     $(CC) $(CGLAGS) -c fw.c

 trie.o : trie.c fw.h trie.h linked.h
     $(CC) $(CGLAGS) -c trie.c

Note the G . 注意G Instead, use this: 而是使用以下命令:

 fw.o : fw.c fw.h trie.h
     $(CC) $(CFLAGS) -c fw.c

 trie.o : trie.c fw.h trie.h linked.h
     $(CC) $(CFLAGS) -c trie.c

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM