c - PETSc 示例不起作用

标签 c makefile cygwin petsc

我有 Windows 7 操作系统。 我已按照 PETSc web page 的说明进行操作;在 VS 2005 的命令提示符中,我打开了 cygwin 并使用以下命令安装了 PETSc:

./configure --with-cc='win32fe cl' --with-fc=0 --with-mpi=0 --download-f2cblaslapack

我尝试从网页运行以下示例:

cd src/ksp/ksp/examples/tutorials

make ex2

ex2.c是c程序代码。我收到以下错误:

$ make ex2

makefile:18: /conf/variables: No such file or directory

makefile:19: /conf/rules: No such file or directory

makefile:1151: /conf/test: No such file or directory

make: *** No rule to make target `/conf/test'.  Stop.

这是什么原因造成的?

(更重要的是) 我该如何修复它?

*编辑:我也可以使用一般性答案,因为目前我什至不知道要 Google 搜索什么,而且我不想只联系 PETSc 支持来解决所有问题。

<小时/>

我决定在 Ubuntu 上工作。现在,事情就这样了。安装后我写:

gcc -I$PETSC_DIR/include -L$PETSC_DIR/$PETSC_ARCH/lib -libpetsc ex2

在命令行中。我收到错误消息:

/usr/bin/ld: cannot find -libpetsc ex2: In function _start': (.text+0x1bc4): multiple definition of_start' /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o:(.text+0x0): first defined here ex2: In function _fini': (.fini+0x0): multiple definition of_fini' /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o:(.fini+0x0): first defined here ex2:(.rodata+0x0): multiple definition of _IO_stdin_used' /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o:(.rodata.cst4+0x0): first defined here ex2: In function__data_start': (.data+0x0): multiple definition of __data_start' /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o:(.data+0x0): first defined here ex2: In function__data_start': (.data+0x8): multiple definition of __dso_handle' /usr/lib/gcc/x86_64-linux-gnu/4.6/crtbegin.o:(.data+0x0): first defined here ex2: In function_init': (.init+0x0): multiple definition of `_init' /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o:(.init+0x0): first defined here collect2: ld returned 1 exit status

最佳答案

PETSc web page 中所述在遇到问题?部分下,了解与 make 相关的问题您需要设置PETSC_DIRPETSC_ARCH由配置打印。

是什么原因造成的?:
makefilesrc/ksp/ksp/examples/tutorials目录指PETSC_DIR包含配置文件,即

include ${PETSC_DIR}/conf/variables
include ${PETSC_DIR}/conf/rules

...
include ${PETSC_DIR}/conf/test

现在当你执行 make 时正如 make ex2 (从错误来看,它表明您尚未设置PETSC_DIR变量),${PETSC_DIR}因此是空的make尝试包括/conf/variables , /conf/rules & /conf/test不存在的文件。

如何修复它?
你必须运行make正如网站上提到的
make PETSC_DIR=<dir_output_from_configure> PETSC_ARCH=<arch_output_from_configure> ex2
在此之前,您需要正确构建源。为了澄清你在问题./configure ...中提到的内容不安装 PETSc,仅配置构建源。您需要运行make 。当您运行configure时如果成功,它将输出配置详细信息,包括 PETSC_DIRPETSC_ARCH 。示例输出:

./configure --with-mpi=0
===============================================================================
             Configuring PETSc to compile on your system                       
===============================================================================
TESTING: alternateConfigureLibrary from PETSc.packages.petsc4py(config/PETSc/packages/petsc4py.py:65)                                                                   Compilers:
...
...
PETSc:
  PETSC_ARCH: arch-linux2-c-debug
  PETSC_DIR: /XXXX/petsc-3.3-p1
  Clanguage: C
  Scalar type: real
  Precision: double
  shared libraries: disabled
  dynamic loading: disabled
  Memory alignment: 16
xxx=========================================================================xxx
 Configure stage complete. Now build PETSc libraries with (cmake build):
   make PETSC_DIR=/XXXX/petsc-3.3-p1 PETSC_ARCH=arch-linux2-c-debug all
 or (experimental with python):
   PETSC_DIR=/XXXX/petsc-3.3-p1 PETSC_ARCH=arch-linux2-c-debug ./config/builder.py
xxx=========================================================================xxx

然后你就运行了make PETSC_DIR=/XXXX/petsc-3.3-p1 PETSC_ARCH=arch-linux2-c-debug allconfigure 的输出中所述。这将构建库。现在您应该能够构建示例了。 (请注意,这是在 Linux 上运行的,您应该几乎能够在 cygwin 上执行相同的操作)
旁注:似乎没有必要设置PETSC_ARCH为了构建示例,您应该能够使用 make PETSC_DIR=<dir_output_from_configure> ex2 进行构建

希望这有帮助!

关于c - PETSc 示例不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11331289/

相关文章:

c - 读取文件后删除所有内容

makefile - 传递参数以在 Makefile 中进行调用

hadoop - Cygwin SSHD 服务在 Windows 中启动和停止

linux - Windows 7 上的 X 服务器

c - 在 8 位寄存器中间存储 4 位值

c - 数组中数字之间的升序排序

static - 根据目标依赖关系使目标包含子目录

c - 使用 makefile 构建 gtk 项目时找不到“gtk/gtk.h”文件

c++ - 如何使 linux 命令行程序在 windows 中运行?

c - 如何计算字符串中的字符数(如果没有占用所有空间)