[petsc-users] makefile for compiling multiple sources

Matthew Knepley knepley at gmail.com
Fri Mar 18 10:04:17 CDT 2016


On Fri, Mar 18, 2016 at 9:49 AM, Matthew Overholt <overholt at capesim.com>
wrote:

> Hi,
>
>
>
> I’m just getting started with PETSc and have been able to configure and
> run the examples, but as I’m starting to put together a more substantial
> code with multiple source files I haven’t been able to find or create a
> makefile which works and follows PETSc guidelines.
>
>
>
> I’ve configured and am building with the Intel compilers and MKL for blas
> & lapack, as per the installation example, and with the C++ language.
>

Use this:

CFLAGS     =
CPPFLAGS   =
LIBFILES   =
TARGET     = femex1
OBJFILES   = femex1.o shapes.o
CLEANFILES = $(TARGET)

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

all: $(TARGET)

$(TARGET) : $(OBJFILES)
       ${CLINKER} -o $(TARGET) $(OBJFILES) ${PETSC_KSP_LIB}


and do not mess around with putting in header file dependencies yourself,
use https://ccache.samba.org/

  Thanks,

    Matt


> Here’s my makefile --------------------------------------
>
> #
>
> # makefile for femex1 - PETSc/kde/ex1.c adapted for FEA
>
> #
>
> # Usage: make all
>
> #        make clean
>
> #
>
> # PETSc was configured using the Intel Compilers, MKL, and C++
>
> #
>
> CFLAGS        =
>
> CPPFLAGS     =
>
> CLFLAGS      =
>
> LIBFILES      = ${PETSC_KSP_LIB}
>
> TARGET        = femex1
>
> CLEANFILES   = $(TARGET)
>
>
>
> include ${PETSC_DIR}/lib/petsc/conf/variables
>
> include ${PETSC_DIR}/lib/petsc/conf/rules
>
>
>
> OBJFILES = femex1.o \
>
>            shapes.o
>
>
>
> all: $(TARGET)
>
>
>
> $(TARGET) : $(OBJFILES) $(LIBFILES)
>
>        ${CLINKER} -o $(TARGET) $(OBJFILES) $(LIBFILES)
>
>
>
> # femex1.cpp has 'main' and PETSc calls
>
> femex1.o: femex1.cpp lists.h shapes.h  chkopts
>
>        ${PETSC_CXXCOMPILE} femex1.cpp
>
>
>
> # shapes.cpp does not have any PETSc calls
>
> shapes.o: shapes.cpp shapes.h
>
>        icpc -c shapes.cpp
>
>
>
> And here’s the result ------------------------------------
>
>
>
> [Matt at HPCL1 mycode]$ make all
>
> /opt/petsc/petsc-3.6.3/linux-gnu-intel/bin/mpicxx -c -wd1572 -g  -fPIC
> -I/opt/petsc/petsc-3.6.3/include
> -I/opt/petsc/petsc-3.6.3/linux-gnu-intel/include      femex1.cpp
>
> icpc -c shapes.cpp
>
> make: *** No rule to make target
> `-Wl,-rpath,/opt/petsc/petsc-3.6.3/linux-gnu-intel/lib', needed by
> `femex1'.  Stop.
>
>
>
> ---------------------------------------------------------------
>
> So it compiles the two sources, but then fails on the linking step.
>
>
>
> Thanks in advance.
>
> Matt Overholt
>
> CapeSym, Inc.
>
>
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient&utm_term=oa-2115-d> This
> email is safe. www.avast.com
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient&utm_term=oa-2115-d>
>



-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20160318/9706c7ae/attachment-0001.html>


More information about the petsc-users mailing list