# CMake cannot find PETSc

**URL:** <https://precice.discourse.group/t/cmake-cannot-find-petsc/273>\
**Category:** Installing preCICE\
**Tags:** cmake, inactive\
**Created:** [May 7, 2020, 3:45pm UTC](https://precice.discourse.group/t/cmake-cannot-find-petsc/273 "2020-05-07T15:45:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gas](https://avatars.discourse-cdn.com/v4/letter/g/8491ac/32.png) [@gas](https://precice.discourse.group/u/gas)\
**Post date:** [May 7, 2020, 3:45pm UTC](https://precice.discourse.group/t/cmake-cannot-find-petsc/273/1 "2020-05-07T15:45:34Z")

</div>

unfortunately I am having trouble when I try to build “preCICE using CMake”

```
  build]$ cmake -DBUILD_SHARED_LIBS=ON ..
.....-- Validating Prettyprint - success
CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:164 (message):
  PETSc could not be found. Be sure to set PETSC_DIR and PETSC_ARCH.
  (missing: PETSC_INCLUDES PETSC_LIBRARIES PETSC_EXECUTABLE_RUNS) (found
  suitable version "3.13.0", minimum required is "3.6")
Call Stack (most recent call first):
  /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:445 (_FPHSA_FAILURE_MESSAGE)
  cmake/modules/FindPETSc.cmake:345 (find_package_handle_standard_args)
  CMakeLists.txt:209 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/guido/precice-2.0.2/build/CMakeFiles/CMakeOutput.log".
See also "/home/guido/precice-2.0.2/build/CMakeFiles/CMakeError.log".

```

I installed PETSc version “3.13.0” from source ,

```
PETSC_DIR /home/guido/petsc/petsc

```

install according [PETSc: Documentation: Installation](https://www.mcs.anl.gov/petsc/documentation/installation.html)

```
./configure
make all test
xxx=========================================================================xxx
 Configure stage complete. Now build PETSc libraries with:
   make PETSC_DIR=/home/guido/petsc/petsc PETSC_ARCH=arch-linux-c-debug all
xxx=========================================================================xxx

build]$ ccmake -DBUILD_SHARED_LIBS=ON ..

PETSC_CURRENT ON 
PETSC_DIR /home/guido/petsc/petsc
ccmake in (t)oggle mode 
PETSC ON  
PETSC_CURRENT ON  
PETSC_DIR /home/guido/petsc/petsc PETSC_INCLUDE_CONF PETSC_INCLUDE_CONF-NOTFOUND  
PETSC_INCLUDE_DIR /home/guido/petsc/petsc/include PETSC_LIBRARY_SINGLE PETSC_LIBRARY_SINGLE-NOTFOUND       
PKG_CONFIG_EXECUTABLE /usr/bin/pkg-config

```

---

<div class="post-metadata">

**Author:** ![gas](https://avatars.discourse-cdn.com/v4/letter/g/8491ac/32.png) [@gas](https://precice.discourse.group/u/gas)\
**Post date:** [May 7, 2020, 3:58pm UTC](https://precice.discourse.group/t/cmake-cannot-find-petsc/273/2 "2020-05-07T15:58:14Z")

</div>

```
.... petsc]$ ls $PETSC_DIR/$PETSC_ARC 
arch-linux-c-debug CODE_OF_CONDUCT.md configure configure.log.bkp gmakefile GNUmakefile interfaces lib linux-precice make.log RDict.log setup.py src
bitbucket-pipelines.yml config configure.log CONTRIBUTING gmakefile.test include Jenkinsfile LICENSE makefile petscdir.mk README.md share systems

[--- petsc]$ ls $PETSC_DIR/$PETSC_ARCH/include 
petscaodef.mod petscdmda.mod petscdmlabel.mod petscdmplexdef.mod petscis.mod petscmatdef.mod .....

```

---

<div class="post-metadata">

**Author:** ![ajaust](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/ajaust/32/160_2.png) [@ajaust](https://precice.discourse.group/u/ajaust)\
**Post date:** [July 19, 2020, 9:23pm UTC](https://precice.discourse.group/t/cmake-cannot-find-petsc/273/3 "2020-07-19T21:23:06Z")

</div>

When compiling PETSc you should choose a prefix (installation directory). Then, after compilation PETSc prints a command for installation (something like `make PETSC_DIR=...`. Did you run this command?

If you do not run this command, you will have incomplete headers, for example, as the files are all copied to the correct location during the `install` step. Your `include/` dir seems to lack the C headers and more. My `include/` of PETSc looks like this for example

```
index.html petscdmdatypes.h.html petscdrawtypes.h petscmatelemental.h petsctao.h.html
makefile petscdmfield.h petscdrawtypes.h.html petscmatelemental.h.html petsctaolinesearch.h
makefile.html petscdmfield.h.html petscds.h petscmath.h petsctaolinesearch.h.html
petsc petscdmforest.h petscds.h.html petscmath.h.html petsctime.h
...

```

---

<div class="post-metadata">

**Author:** ![fsimonis](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/fsimonis/32/6_2.png) [@fsimonis](https://precice.discourse.group/u/fsimonis)\
**Post date:** [October 1, 2020, 9:08am UTC](https://precice.discourse.group/t/cmake-cannot-find-petsc/273/4 "2020-10-01T09:08:00Z")

</div>

@gas The PETSc website now states that one should use the generated pkg-config file to detect PETSc from CMake. I developed a wrapper which is backward compatible with the previous use of PETSc and should resolve most of the PETSc-related issues.

> <https://github.com/precice/precice/pull/754>

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/precice/original/1X/67d2a5fa6f80e597e2267ff17fa8c1673cd11caa.svg) [@system](https://precice.discourse.group/u/system)\
**Post date:** [May 16, 2022, 12:37pm UTC](https://precice.discourse.group/t/cmake-cannot-find-petsc/273/5 "2022-05-16T12:37:59Z")

</div>

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
