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

标签 c makefile

我有一个 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/

相关文章:

c - 以最有效的方式逐行阅读*平台特定*

c++ - 如何将c/c++回调函数转换为delphi

c++ - 如何通过读取文件将不同数据类型的数据推送到一个 vector 中?

c - 生成对象数据用作函数参数的语法导致错误

windows - 为 Windows 上的 Lua 构建 lua 文件系统

c++ - 获取 make 项目编译和包含的文件列表

linux - ft-models.out makefile 错误

android - 作为 : unrecognized option '-EL' while compiling android kernel on ubuntu 14

c - 可变参数宏 - 省略号前的逗号?

makefile - 使用 MinGW/MSYS 编译 OpenSSL 时出错