[petsc-users] Compiling Fortran Code

Balay, Satish balay at mcs.anl.gov
Wed Mar 13 19:44:46 CDT 2019


check petsc makefile format - for ex: src/tao/unconstrained/examples/tutorials/makefile

Also rename your fortran sources that have petsc calls from .f to .F


On Wed, 13 Mar 2019, Matthew Knepley via petsc-users wrote:

> On Wed, Mar 13, 2019 at 7:36 PM Maahi Talukder via petsc-users <
> petsc-users at mcs.anl.gov> wrote:
> 
> > Dear All,
> >
> > I am trying to compile a Fortran code. The make is as it follows-
> >
> >
> > ............................................................................................................................................................................................................................
> > # Makefile for egrid2d
> >
> > OBJS = main.o egrid2d.o
> >
> > FFLAGS = -I/home/maahi/petsc/include
> > -I/home/maahi/petsc/arch-linux2-c-debug/include -Ofast -fdefault-real-8
> >
> > #
> > # link
> > #
> > include ${PETSC_DIR}/lib/petsc/conf/variables
> > include ${PETSC_DIR}/lib/petsc/conf/rules
> >
> > egrid2d: $(OBJS)
> >
> > ${FLINKER}  $(OBJS)  -o egrid2d ${PETSC_LIB}
> >
> 
> Move this above your includes
> 
The location is fine. Can you change OBJS to a different name - say OBJ [or something else] and see if that works.

Satish

> 
> >
> > #
> > # compile
> > #
> > main.o:
> >    ${FLINKER} -c $(FFLAGS) main.f  ${PETSC_LIB}
> >
> 
> You should not need this rule.
> 
>   Thanks,
> 
>     Matt
> 
> 
> > #
> > # Common and Parameter Dependencies
> > #
> >
> > main.o:        main.f        par2d.f
> > egrid2d.o:     egrid2d.f     par2d.f
> >
> > .....................................................................................................................................................................................................................................
> >
> > But I get the following error-
> >
> >
> > ..............................................................................................................................................................................
> > /home/maahi/petsc/arch-linux2-c-debug/bin/mpif90 -Wall
> > -ffree-line-length-0 -Wno-unused-dummy-argument -g
> > -I/home/maahi/petsc/include -I/home/maahi/petsc/arch-linux2-c-debug/include
> > -Ofast -fdefault-real-8      -o egrid2d
> > -Wl,-rpath,/home/maahi/petsc/arch-linux2-c-debug/lib
> > -L/home/maahi/petsc/arch-linux2-c-debug/lib
> > -Wl,-rpath,/home/maahi/petsc/arch-linux2-c-debug/lib
> > -L/home/maahi/petsc/arch-linux2-c-debug/lib
> > -Wl,-rpath,/usr/lib/gcc/x86_64-redhat-linux/7
> > -L/usr/lib/gcc/x86_64-redhat-linux/7 -lpetsc -lflapack -lfblas -lm
> > -lpthread -lstdc++ -ldl -lmpifort -lmpi -lgfortran -lm -lgfortran -lm
> > -lgcc_s -lquadmath -lstdc++ -ldl
> > /*usr/lib/gcc/x86_64-redhat-linux/7/../../../../lib64/crt1.o: In function
> > `_start':*
> > *(.text+0x20): undefined reference to `main'*
> > collect2: error: ld returned 1 exit status
> > make: *** [makefile:18: egrid2d] Error 1
> >
> > ........................................................................................................................................
> >
> > Any idea how to fix it ?
> >
> > Thanks,
> > Maahi Talukder
> >
> >
> >
> >
> 
> 



More information about the petsc-users mailing list