[petsc-users] C++ Makefile for PETSc program

Satish Balay balay at mcs.anl.gov
Wed Aug 29 12:55:57 CDT 2018


Easiest thing to do is have the sourcefiles, objfiles and the
executable in the same dir - and use PETSc example makefile format.

For more involved makefile [with objfiles, makefile, sourcefiles in
different locations] - one can look at PETSC_DIR/gmakefile - but that
is hard to parse.

Satish

On Wed, 29 Aug 2018, Justin Dong wrote:

> Hi all,
> 
> I have a program with C++ that I am trying to integrate with PETSc on MacOS
> X. My Makefile looks like this
> 
> #-----[Makefile]------
> > include ${PETSC_DIR}/lib/petsc/conf/variables
> > include ${PETSC_DIR}/lib/petsc/conf/rules
> > include ${PETSC_DIR}/lib/petsc/conf/test
> >
> 
> 
> > #----[Directories]----
> > oPath = obj
> > sPath = src
> > iPath = inc $(PETSC_LIB)
> > #====================
> >
> 
> 
> > #---[Compiler and Settings]-----
> > compiler = g++-8
> > compilerFlags = -std=c++11 -Wall -lm -llapack -lblas -O3
> > paths  = -I./$(iPath)
> > #======================
> >
> 
> 
> > #----[Variable Names]-------
> > headers = $(wildcard $(iPath)/*.hpp)
> > sources = $(wildcard $(sPath)/*.cpp)
> > objects = $(subst $(sPath)/,$(oPath)/,$(sources:.cpp=.o))
> > #==========================
> >
> 
> 
> > #----[Compilation]---------
> > main:$(objects) $(headers) main.cpp
> > $(compiler) $(compilerFlags) -o main $(objects) main.cpp $(PETSC_LIB)
> > $(paths)
> > $(oPath)/%.o:$(sPath)/%.cpp $(subst $(sPath)/, $(iPath)/,$(<:.cpp=.hpp))
> > @mkdir -p $(@D)
> > $(compiler) $(compilerFlags) -o $@ -c $(paths) $<
> >
> 
> 
> > #-----[Clean up]-------
> > # clean:rm main
> > # rm -rf $(oPath)/
> 
> 
> When I try to include "petsc.h", I get a "no such file or directory" error.
> I have PETSC_DIR and PETSC_ARCH set correctly, but I'm not the most
> proficient with Make. Can someone provide some tips on how to get this
> working properly?
> 
> Best,
> Justin
> 



More information about the petsc-users mailing list