Makefile for compiling multiple source files

Vijay M vijay.m at gmail.com
Mon May 14 11:22:24 CDT 2007


Running "mpif77 -show" gives the following output

g77: unrecognized option `-show'
/usr/lib/gcc/x86_64-redhat-linux/3.4.6/libfrtbegin.a(frtbegin.o)(.text+0x1e):
In function `main':
: undefined reference to `MAIN__'
collect2: ld returned 1 exit status
mpif77: No such file or directory

I dont think that is a valid option in the current version of gcc i am using.

Otherwise, when i try to compile and run the tutorial examples,
everything works perfectly. Hence, both the c and fortran compiler are
working as expected. I have attached the detailed commands with all
linker options used for the compilation.
================================================
[vijay at linux src]$ cd ~/work/petsc/src/ksp/ksp/examples/tutorials

[vijay at linux tutorials]$ make ex2
mpicc -c -fPIC -Wall -Wwrite-strings -Wno-strict-aliasing -g3
-I/home/vijay/work/petsc/src/dm/mesh/sieve -I/home/vijay/work/petsc
-I/home/vijay/work/petsc/bmake/linux-gnu-c-debug
-I/home/vijay/work/petsc/include -I/usr/include
-D__SDIR__="src/ksp/ksp/examples/tutorials/" ex2.c

mpicc -fPIC -Wall -Wwrite-strings -Wno-strict-aliasing -g3  -o ex2
ex2.o  -Wl,-rpath,/home/vijay/work/petsc/lib/linux-gnu-c-debug
-L/home/vijay/work/petsc/lib/linux-gnu-c-debug -lpetscksp -lpetscdm
-lpetscmat -lpetscvec -lpetsc     -llapack -lblas -lm
-Wl,-rpath,/usr/lib64 -L/usr/lib64
-Wl,-rpath,/usr/lib/gcc/x86_64-redhat-linux/3.4.6
-L/usr/lib/gcc/x86_64-redhat-linux/3.4.6
-Wl,-rpath,/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../lib64
-L/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../lib64
-Wl,-rpath,/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../..
-L/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../..
-Wl,-rpath,/lib/../lib64 -L/lib/../lib64 -Wl,-rpath,/usr/lib/../lib64
-L/usr/lib/../lib64 -ldl -llammpio -llamf77mpi -lmpi -llam -laio
-lutil -lgcc_s -lpthread -lg2c -lm -Wl,-rpath,/usr/lib64
-Wl,-rpath,/usr/lib/gcc/x86_64-redhat-linux/3.4.6
-Wl,-rpath,/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../lib64
-Wl,-rpath,/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../..
-Wl,-rpath,/lib/../lib64 -Wl,-rpath,/usr/lib/../lib64 -lm
-Wl,-rpath,/usr/lib64 -L/usr/lib64
-Wl,-rpath,/usr/lib/gcc/x86_64-redhat-linux/3.4.6
-L/usr/lib/gcc/x86_64-redhat-linux/3.4.6
-Wl,-rpath,/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../lib64
-L/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../lib64
-Wl,-rpath,/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../..
-L/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../..
-Wl,-rpath,/lib/../lib64 -L/lib/../lib64 -Wl,-rpath,/usr/lib/../lib64
-L/usr/lib/../lib64 -ldl -llammpio -llamf77mpi -lmpi -llam -laio
-lutil -lgcc_s -lpthread -ldl
/bin/rm -f ex2.o

[vijay at linux tutorials]$ make ex2f
mpif77 -c  -fPIC -Wall -g   -I/home/vijay/work/petsc
-I/home/vijay/work/petsc/bmake/linux-gnu-c-debug
-I/home/vijay/work/petsc/include -I/usr/include        -o ex2f.o
ex2f.F

mpif77 -fPIC -Wall -g   -o ex2f ex2f.o
-Wl,-rpath,/home/vijay/work/petsc/lib/linux-gnu-c-debug
-L/home/vijay/work/petsc/lib/linux-gnu-c-debug -lpetscksp -lpetscdm
-lpetscmat -lpetscvec -lpetsc     -llapack -lblas -lm
-Wl,-rpath,/usr/lib64 -L/usr/lib64
-Wl,-rpath,/usr/lib/gcc/x86_64-redhat-linux/3.4.6
-L/usr/lib/gcc/x86_64-redhat-linux/3.4.6
-Wl,-rpath,/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../lib64
-L/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../lib64
-Wl,-rpath,/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../..
-L/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../..
-Wl,-rpath,/lib/../lib64 -L/lib/../lib64 -Wl,-rpath,/usr/lib/../lib64
-L/usr/lib/../lib64 -ldl -llammpio -llamf77mpi -lmpi -llam -laio
-lutil -lgcc_s -lpthread -lg2c -lm -Wl,-rpath,/usr/lib64
-Wl,-rpath,/usr/lib/gcc/x86_64-redhat-linux/3.4.6
-Wl,-rpath,/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../lib64
-Wl,-rpath,/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../..
-Wl,-rpath,/lib/../lib64 -Wl,-rpath,/usr/lib/../lib64 -lm
-Wl,-rpath,/usr/lib64 -L/usr/lib64
-Wl,-rpath,/usr/lib/gcc/x86_64-redhat-linux/3.4.6
-L/usr/lib/gcc/x86_64-redhat-linux/3.4.6
-Wl,-rpath,/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../lib64
-L/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../lib64
-Wl,-rpath,/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../..
-L/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../..
-Wl,-rpath,/lib/../lib64 -L/lib/../lib64 -Wl,-rpath,/usr/lib/../lib64
-L/usr/lib/../lib64 -ldl -llammpio -llamf77mpi -lmpi -llam -laio
-lutil -lgcc_s -lpthread -ldl
/bin/rm -f ex2f.o
================================================
Satish, the only difference between these examples and my code is that
i have multiple files to compile with and without petsc calls and each
mpif77 call does not create an object file but instead tries to link
and create an output executable. I am not sure how to get around this.
Any ideas ?

Vijay

On 5/14/07, Satish Balay <balay at mcs.anl.gov> wrote:
>
> Looks like this is a problem with your mpif77.
>
> What do you have for:
>
> mpif77 -show
>
> Did PETSc configure fine with it? Are you able to run PETSc examples?
>
> cd src/ksp/ksp/examples/tutorials
> make ex2
> make ex2f
>
> Satish
>
> On Mon, 14 May 2007, Vijay M wrote:
>
> > Satish,
> >
> > Thanks for the reply. I modified your makefile (which is quite close
> > to what i had to start with) and when i run it, I get an error message
> > to the effect
> >
> > mpif77 -c  -fPIC -Wall -g   -I/home/vijay/work/petsc
> > -I/home/vijay/work/petsc/bmake/linux-gnu-c-debug
> > -I/home/vijay/work/petsc/include -I/usr/include        -o C.o C.F90
> > g77: C.F90: linker input file unused because linking not done
> >
> > mpif77 -c  -fPIC -Wall -g    -o A.o A.f90
> > g77: A.f90: linker input file unused because linking not done
> >
> > This is repeated for all source files. Hence when the linker command
> > is issued, there are no object files created in my local directory. I
> > observed this message previously and hence went through the manual cpp
> > route. Do i have to set some environment or configuration variable to
> > get this working ?
> >
> > Vijay
> >
> >
> > On 5/14/07, Satish Balay <balay at mcs.anl.gov> wrote:
> > >
> > > On Mon, 14 May 2007, Vijay M wrote:
> > >
> > > > Hi,
> > > >
> > > > I've been trying to use PETSc for one of my projects lately and I was
> > > > wondering how to create the makefile to compile multiple source files
> > > > with and without PETSc calls in fortran efficiently. I am sure it is a
> > > > newbie question but I could not find much information about this
> > > > anywhere.
> > > >
> > > > For example, you could take 4 files. A.f90, B.f90 without petsc calls
> > > > and C.f90 and D.f90 with petsc calls. If I were to compile them I have
> > > > to use
> > >
> > > If C, D are PETSc sources, then they should be C.F90, D.F90 [not .f90
> > > sufix]
> > >
> > > >
> > > > f90 -c A.f90 -o A.o
> > > > f90 -c B.f90 -o B.o
> > > > cpp C.f90 -I<include dir> > Ctemp.f90
> > > > f90 -c Ctemp.f90 -o C.o
> > > > cpp  D.f90 -I<include dir> > Dtemp.f90
> > > > f90 -c Dtemp.f90 -o D.o
> > > >
> > > > g77 <PETSC options> A.o B.o C.o D.o -o out.exe
> > >
> > > this assumes A.o has the main subroutine - if not - you should list
> > > the corresponding .o file first.
> > >
> > > >
> > > > PETSc is configured to use g77 as the linker in my server but since I
> > > > am compiling each file separately, I cannot quite use the linker
> > > > directly (It treats the source as a linker script). Is there a
> > > > simplified way to do this or have I missed something vital ?!
> > >
> > >
> > > I'm attaching a suitable PETSc makefile for your config.
> > >
> > > Satish
> > >
> > > > I would appreciate any kind of help you can provide. If you need more
> > > > information, let me know. Thanks.
> > > >
> > > > vijay
> > > >
> > > >
> > >
> >
> >
>
>




More information about the petsc-users mailing list