[petsc-users] How to link petsc?

Jed Brown jed at jedbrown.org
Sun Oct 1 17:26:20 CDT 2017


Either use the PETSc makefiles or use pkg-config.  This is a pretty
comprehensive makefile you can use:


PETSc.pc := $(PETSC_DIR)/$(PETSC_ARCH)/lib/pkgconfig/PETSc.pc

CC := $(shell pkg-config --variable=ccompiler $(PETSc.pc))
CXX := $(shell pkg-config --variable=cxxcompiler $(PETSc.pc))
FC := $(shell pkg-config --variable=fcompiler $(PETSc.pc))
CFLAGS := $(shell pkg-config --variable=cflags_extra $(PETSc.pc)) $(shell pkg-config --cflags-only-other $(PETSc.pc))
CPPFLAGS := $(shell pkg-config --cflags-only-I $(PETSc.pc))
LDFLAGS := $(shell pkg-config --libs-only-L --libs-only-other $(PETSc.pc))
LDFLAGS += $(patsubst -L%, $(shell pkg-config --variable=ldflag_rpath $(PETSc.pc))%, $(shell pkg-config --libs-only-L $(PETSc.pc)))
LDLIBS := $(shell pkg-config --libs-only-l $(PETSc.pc)) -lm

print:
	@echo CC=$(CC)
	@echo CFLAGS=$(CFLAGS)
	@echo CPPFLAGS=$(CPPFLAGS)
	@echo LDFLAGS=$(LDFLAGS)
	@echo LDLIBS=$(LDLIBS)


Klaus Burkart <k_burkart at yahoo.com> writes:

> I installed petsc and the tests were successful on Ubuntu 16.04
>
> PETSC_DIR points to the install directory in my home directory and is in my .bashrc  export PETSC_DIR=/home/klaus/petsc-3.7.6
>
>
> Now I want to link it and use it with the standard linux compiler to use the functionality in my application but I encounter several issues leading to compiler errors when I try to compile my own application including petsc functionality.
>
> I must use absolute path to petsc header files in my source code, Makefile entries to the install directors are not recognized.  Even then, header files referenced in petsc.h are not found leading to the following error .. petsc-3.7.6/include/petsc.h:5:22: fatal error: petscbag.h: file or directory not found  but the file is in the same directory. Adding the other header files also with the absolute path doesn't work, it's not going beyond petsc.h, the error remains
>
>
>
> What's the correct setup to be able to compile applications including petsc functionality?


More information about the petsc-users mailing list