linux - 原始 makefile 编译失败

标签 linux makefile

我正在尝试学习makefile,但我失败得很厉害。 一个例子(非常原始),但我应该理解它才能继续,就是这个

f90_simple: f1.o  
    gfortran f1.o
     mv a.out f90_simple  
f90_simple.o:   f1.f90
    gfortran -c f1.f90

它不起作用,我收到此错误 我收到此错误

make: *** No rule to make target `f1.o', needed by `f90_simple'.  Stop.

你能给我建议吗?

谢谢

最佳答案

您的第一条规则规定,在构建 f90_simple 之前,必须构建目标 f1.o

但是 makefile 中没有规则告诉 make 如何构建目标 f1.o,并且 make 找不到任何可以构建它的内置规则(基于 make 可用的源文件),因此它会打印该错误。

您确实有一条规则告诉 make 如何构建目标 f90_simple.o...但这不是 make 正在寻找的目标。您很可能希望您的 makefile 是:

f90_simple: f1.o  
        gfortran $^
        mv a.out $@

f1.o: f1.f90
        gfortran -o $@ -c $<

否则:

f90_simple: f90_simple.o  
        gfortran $^
        mv a.out $@

f90_simple.o: f1.f90
        gfortran -o $@ -c $<

但你不能混合搭配它们,否则 make 不知道该怎么办。

我认为至少阅读 The GNU Make Manual 中的介绍性章节您确实会受益匪浅。 .

关于linux - 原始 makefile 编译失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44349439/

相关文章:

c++ - 录制成WAV文件

java - 无效文件(坏魔数(Magic Number)): Exec format error

linux - check_snmp_mem.pl 中的内存使用值是如何得出的?

shell - 在 Makefile 中使用 shell 查找 Ubuntu 版本

python - python 的 shutil.copyfile() 是原子的吗?

linux - 在 Linux 上构建 Windows perl 模块

twitter-bootstrap - 编译 Twitter bootstrap 3 文档(如何)?

c++ - 在 g++ 中生成 "-L"和 -rpath 标志的等效函数是什么

makefile - 如何在 GNU make 中制作目标 "private"仅供内部使用?或 : how to best enforce target-specific variable-values?

linux - RTL8821CE(wifi)驱动安装问题: KBUILD_MODNAME