I want to use PETSc
in a cpp
code. I installed PETSc
and when run the cmd echo $PETSC_DIR
I got the path to the library.
I make a hello world code and
#include "petsc.h"
#include <iostream>
int main()
{
std::cout << "Hello Wold" << std:endl;
}
and the CMakeLists.txt
is as follows:
cmake_minimum_required(VERSION 3.20.3)
project(ddm_library)
include_directories(include)
file(GLOB SOURCES "src/*.cc")
add_executable(main ${SOURCES})
and run following cmds
mkdir build
cd build
cmake CMAKE_INCLUDE_PATH=/opt/petsc/linux-c-opt/include ..
make
When I run the last cmd I got the following error
/home/main.cc:5:10: fatal error: petsc.h: No such file or directory
5 | #include "petsc.h"
| ^~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/main.dir/build.make:76: CMakeFiles/main.dir/src/main.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/main.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
Where did I make a mistake?
I changed
CMakeLists.txt
and usefind_package(PkgConfig)
, now it works. The final version ofCMakeLists.txt
is like this