gpt4 book ai didi

c - 新手 : what is wrong with my makefile?

转载 作者:太空宇宙 更新时间:2023-11-04 01:29:01 25 4
gpt4 key购买 nike

我有一个 makefile,在最后提供,还有一些关于它的问题:

  1. clean: 部分的作用是什么?
  2. -c 部分是什么意思? (在 Google 上搜索 gcc -c explained 和其他变体后,我得到了首字母缩写为 GCC 的大学。)
  3. 当我尝试运行 make 时,出现此错误,但文件 lab3p2.c 确实存在。怎么了?

    gcc –c lab3p2.c
    gcc: –c: No such file or directory
    make: *** [lab3p2.o] Error 1

生成文件

all: lab3p2

lab3p2: lab3p2.o lab3p2f1.o lab3p2f2.o lab3p2f3.o
gcc lab3p2.o lab3p2f1.o lab3p2f2.o lab3p2f3.o –o lab3p2

lab3p2.o: lab3p2.c
gcc –c lab3p2.c

lab3p2f1.o: lab3p2f1.c
gcc –c lab3p2f1.c

lab3p2f2.o: lab3p2f2.c
gcc –c lab3p2f2.c

lab3p2f3.o: lab3p2f3.c
gcc –c lab3p2f3.c

clean:
rm –rf *.o lab3p2

最佳答案

what does the "clean:" part do?

Makefile 的clean 规则通常用于删除Makefile 生成的任何已编译文件。在这种情况下,已编译的目标文件(.o 文件)和 lab3p2 文件将被删除。

因为 clean 不是生成的文件,所以它应该是 phony rule :

clean:
rm –rf *.o lab3p2

.PHONY: clean

what does the "-c" part mean? (google search "gcc -c explained" and other variations gives me a college with the acronym gcc, blah)

这意味着编译源文件,但不运行链接器。来自man page :

-c  Compile or assemble the source files, but do not link.  The linking stage    simply is not done.  The ultimate output is in the form of an object file    for each source file.

I get this error:

gcc –c lab3p2.c
gcc: –c: No such file or directory
make: *** [lab3p2.o] Error 1

是一个破折号,它应该是 hyphen-minus (-).

关于c - 新手 : what is wrong with my makefile?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26268566/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com