编译包含 PETSc 库的 C++ 代码 make:无规则生成目标错误信息

问题描述

我对使用所讨论的开放源代码感兴趣 herehere 讨论了框架和有关如何运行代码的一些说明。为了能够使用代码,首先应该安装 PETSc。我已经这样做了,它似乎已正确安装。当我尝试按照 paper(第 2.2 节)中给出的说明运行 make topopt 时,问题出现了。在 GitHub 上存在一个 makefile_ref,按照 paper 中给出的说明,我进行了以下更改:PETSC_DIR=\home\myusername\petscPETSC_ARCH=arch-linux-c-debug。运行 make -d topopt 后,我收到以下错误:

GNU Make 4.2.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2016 Free Software Foundation,Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY,to the extent permitted by law.
Reading makefiles...
Updating makefiles....
 Considering target file 'GNUmakefile'.
  File 'GNUmakefile' does not exist.
  Looking for an implicit rule for 'GNUmakefile'.
  Trying pattern rule with stem 'GNUmakefile'.
  Trying implicit prerequisite 'GNUmakefile.o'.
  Trying pattern rule with stem 'GNUmakefile'.
  Trying implicit prerequisite 'GNUmakefile.c'.
  Trying pattern rule with stem 'GNUmakefile'.
  Trying implicit prerequisite 'GNUmakefile.cc'.
  Trying pattern rule with stem 'GNUmakefile'.
  Trying implicit prerequisite 'GNUmakefile.C'.
  Trying pattern rule with stem 'GNUmakefile'.
  Trying implicit prerequisite 'GNUmakefile.cpp'.
  Trying pattern rule with stem 'GNUmakefile'.
  Trying implicit prerequisite 'GNUmakefile.p'.
  Trying pattern rule with stem 'GNUmakefile'.
  Trying implicit prerequisite 'GNUmakefile.f'.
  Trying pattern rule with stem 'GNUmakefile'.
  Trying implicit prerequisite 'GNUmakefile.F'.
  Trying pattern rule with stem 'GNUmakefile'.
  Trying implicit prerequisite 'GNUmakefile.m'.
  Trying pattern rule with stem 'GNUmakefile'.
  Trying implicit prerequisite 'GNUmakefile.r'.
  Trying pattern rule with stem 'GNUmakefile'.
  Trying implicit prerequisite 'GNUmakefile.s'.
  Trying pattern rule with stem 'GNUmakefile'.
  Trying implicit prerequisite 'GNUmakefile.S'.
  Trying pattern rule with stem 'GNUmakefile'.
  Trying implicit prerequisite 'GNUmakefile.mod'.
  Trying pattern rule with stem 'GNUmakefile'.
  Trying implicit prerequisite 'GNUmakefile.sh'.
  Trying pattern rule with stem 'GNUmakefile'.
  Trying implicit prerequisite 'GNUmakefile,v'.
  Trying pattern rule with stem 'GNUmakefile'.
  Trying implicit prerequisite 'RCS/GNUmakefile,v'.
  Trying pattern rule with stem 'GNUmakefile'.
  Trying implicit prerequisite 'RCS/GNUmakefile'.
  Trying pattern rule with stem 'GNUmakefile'.
  Trying implicit prerequisite 's.GNUmakefile'.
  Trying pattern rule with stem 'GNUmakefile'.
  Trying implicit prerequisite 'SCCS/s.GNUmakefile'.
  Trying pattern rule with stem 'GNUmakefile'.
  Trying implicit prerequisite 'GNUmakefile.o'.
  Looking for a rule with intermediate file 'GNUmakefile.o'.
   Avoiding implicit rule recursion.
   Trying pattern rule with stem 'GNUmakefile'.
   Trying implicit prerequisite 'GNUmakefile.c'.
   Trying pattern rule with stem 'GNUmakefile'.
   Trying implicit prerequisite 'GNUmakefile.cc'.
   Trying pattern rule with stem 'GNUmakefile'.
   Trying implicit prerequisite 'GNUmakefile.C'.
   Trying pattern rule with stem 'GNUmakefile'.
   Trying implicit prerequisite 'GNUmakefile.cpp'.
   Trying pattern rule with stem 'GNUmakefile'.
   Trying implicit prerequisite 'GNUmakefile.p'.
   Trying pattern rule with stem 'GNUmakefile'.
   Trying implicit prerequisite 'GNUmakefile.f'.
   Trying pattern rule with stem 'GNUmakefile'.
   Trying implicit prerequisite 'GNUmakefile.F'.
   Trying pattern rule with stem 'GNUmakefile'.
   Trying implicit prerequisite 'GNUmakefile.m'.
   Trying pattern rule with stem 'GNUmakefile'.
   Trying implicit prerequisite 'GNUmakefile.r'.
   Trying pattern rule with stem 'GNUmakefile'.
   Trying implicit prerequisite 'GNUmakefile.s'.
   Trying pattern rule with stem 'GNUmakefile'.
   Trying implicit prerequisite 'GNUmakefile.S'.
   Trying pattern rule with stem 'GNUmakefile'.
   Trying implicit prerequisite 'GNUmakefile.mod'.
   Trying pattern rule with stem 'GNUmakefile.o'.
   Trying implicit prerequisite 'GNUmakefile.o,v'.
   Trying pattern rule with stem 'GNUmakefile.o'.
   Trying implicit prerequisite 'RCS/GNUmakefile.o,v'.
   Trying pattern rule with stem 'GNUmakefile.o'.
   Trying implicit prerequisite 'RCS/GNUmakefile.o'.
   Trying pattern rule with stem 'GNUmakefile.o'.
   Trying implicit prerequisite 's.GNUmakefile.o'.
   Trying pattern rule with stem 'GNUmakefile.o'.
   Trying implicit prerequisite 'SCCS/s.GNUmakefile.o'.
   Trying pattern rule with stem 'GNUmakefile'.
   Trying implicit prerequisite 'GNUmakefile.c'.
   Looking for a rule with intermediate file 'GNUmakefile.c'.
    Avoiding implicit rule recursion.
    Avoiding implicit rule recursion.
    Trying pattern rule with stem 'GNUmakefile'.
    Trying implicit prerequisite 'GNUmakefile.y'.
    Trying pattern rule with stem 'GNUmakefile'.
.
.
.
.
.
.
.
.
.
.
Looking for a rule with intermediate file 'topopt.mod'.
   Avoiding implicit rule recursion.
   Avoiding implicit rule recursion.
   Trying pattern rule with stem 'topopt.mod'.
   Trying implicit prerequisite 'topopt.mod,v'.
   Trying pattern rule with stem 'topopt.mod'.
   Trying implicit prerequisite 'RCS/topopt.mod,v'.
   Trying pattern rule with stem 'topopt.mod'.
   Trying implicit prerequisite 'RCS/topopt.mod'.
   Trying pattern rule with stem 'topopt.mod'.
   Trying implicit prerequisite 's.topopt.mod'.
   Trying pattern rule with stem 'topopt.mod'.
   Trying implicit prerequisite 'SCCS/s.topopt.mod'.
 Trying pattern rule with stem 'topopt'.
 Rejecting impossible implicit prerequisite 'topopt.c'.
 Trying pattern rule with stem 'topopt'.
 Rejecting impossible implicit prerequisite 'topopt.cc'.
 Trying pattern rule with stem 'topopt'.
 Rejecting impossible implicit prerequisite 'topopt.C'.
 Trying pattern rule with stem 'topopt'.
 Rejecting impossible implicit prerequisite 'topopt.cpp'.
 Trying pattern rule with stem 'topopt'.
 Rejecting impossible implicit prerequisite 'topopt.p'.
 Trying pattern rule with stem 'topopt'.
 Rejecting impossible implicit prerequisite 'topopt.f'.
 Trying pattern rule with stem 'topopt'.
 Rejecting impossible implicit prerequisite 'topopt.F'.
 Trying pattern rule with stem 'topopt'.
 Rejecting impossible implicit prerequisite 'topopt.m'.
 Trying pattern rule with stem 'topopt'.
 Rejecting impossible implicit prerequisite 'topopt.r'.
 Trying pattern rule with stem 'topopt'.
 Rejecting impossible implicit prerequisite 'topopt.s'.
 Trying pattern rule with stem 'topopt'.
 Rejecting impossible implicit prerequisite 'topopt.S'.
 Trying pattern rule with stem 'topopt'.
 Rejecting impossible implicit prerequisite 'topopt.mod'.
 Trying pattern rule with stem 'topopt'.
 Trying implicit prerequisite 'topopt.sh'.
 Looking for a rule with intermediate file 'topopt.sh'.
  Avoiding implicit rule recursion.
  Trying pattern rule with stem 'topopt.sh'.
  Trying implicit prerequisite 'topopt.sh,v'.
  Trying pattern rule with stem 'topopt.sh'.
  Trying implicit prerequisite 'RCS/topopt.sh,v'.
  Trying pattern rule with stem 'topopt.sh'.
  Trying implicit prerequisite 'RCS/topopt.sh'.
  Trying pattern rule with stem 'topopt.sh'.
  Trying implicit prerequisite 's.topopt.sh'.
  Trying pattern rule with stem 'topopt.sh'.
  Trying implicit prerequisite 'SCCS/s.topopt.sh'.
 No implicit rule found for 'topopt'.
 Finished prerequisites of target file 'topopt'.
Must remake target 'topopt'.
make: *** No rule to make target 'topopt'.  Stop.

上面的代码只是整个消息的一小部分(开始部分和结束部分)。

我正在使用 Ubuntu 20.04。

提前致谢。

解决方法

存在一个 makefile_ref,其中按照论文中给出的说明进行了以下更改 [...]

如果没有指定要读取的 makefile 的显式选项,make 实用程序会通过多个替代名称查找输入文件。 makefile_ref 不是其中之一。我将文件名的“_ref”部分作为“引用”的助记符,从这个角度来看,意图似乎是您将 makefile_ref 复制到,例如,makefile(文件名之一) make 默认查找),并修改副本以适合您的环境。

,

答案:

事实证明,编译 GitHub 上给出的拓扑优化代码毕竟不是那么复杂。 在这里,我重申了关于 GitHub 的说明,并提供了更多细节。

要使用 PETSc 运行拓扑优化开源代码,首先需要安装 PETSc。您应该注意,要安装 PETSc,您将需要安装 BLAS 和 LAPACK 库,这非常简单,说明在 PETSc 中给出。现在系统上安装了 PETSc,只需从 GitHub 克隆 TopOpt_in_PETSc。

您会找到一个名为 makefile_ref 的文件,将文件名更改为 makefile 然后打开它并在代码的前两行修改路径,这将是这样的 { {1}} 和 PETSC_DIR=/home/username/petsc(这是我的情况,可能因您的机器而异)。前者是本地机器上安装 PETSc 的目录路径,后者是 PETSc 的构建名称。

上述操作完成后,您可以运行 PETSC_ARCH=arch-linux-c-debug,它会为您构建一个名为 make topopt 的可执行文件。按照 paper 中给出的说明,您将能够运行拓扑优化模拟。

备注:上面给出的安装说明是在 ubuntu 20.04 LTS 上执行的,尽管 PETSc 也与 Windows 和 iOS 甚至 Android 兼容。另一方面,TopOpt_in_PETSc 是在 linux 上开发和实现的,可能需要进一步操作才能安装在 Windows 上。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...