Fortran Preprocessor Definition Failed in Makefile

Fortran Preprocessor Definition Failed in Makefile

Dear All,

I have a cross-platform parallel program developed under windows, windows-cygwin and linux.

When use VS2010 to invoke the FPP and set the preprocessor definitions to "WINDOWS", the code can be compiled and works fine (result 1). But when use windows-cygwin, the Preprocessor Definition "CYGWIN" can not be recognized (result 2), but the code can be compiled to executable as well.

Maybe the configure in makefile is not corrected (It works fine if I have no preprocessor definition). I am not so familar with makefile's format.

Thanks.

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Result!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Result 1:

Hello World

Solved in WINDOWS

Result 2:

Hello World

Unknow

!!!!!!!!!!!!!!!!!!!!!!!!!!Sample Codes!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

!!Main

program Main

    use Solver    
    implicit none

    ! Variables

    ! Body of Main
    print *, 'Hello World'
    
    call Solve
        

end program Main

!!Module

Module Solver
    
    implicit none

#ifdef CYGWIN
#include <finclude/petscsys.h>
#include <finclude/petscvec.h>
#include <finclude/petscmat.h>
#include <finclude/petscpc.h>
#include <finclude/petscksp.h>

#include <finclude/petscvec.h90>
#include <finclude/petscmat.h90>
#include <finclude/petscksp.h90>
#include <finclude/petscpc.h90>
#endif
    
contains

subroutine Solve()
    implicit none
#ifdef WINDOWS    
    write(*,*) "Solved in WINDOWS"
#elif CYGWIN
    write(*,*) "Solved in CYGWIN"
#else
    write(*,*) "Unknow"
#endif
end subroutine Solve

end Module Solver

!!Makefile

# Makefile

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

#FC = ifort
MODEL =../Main/
# Additional flags that may be required by the compiler ...
# DFCFLAG = -em  # When using Cray Fortran compiler
#DFCFLAG =

FPPFLAGS = -fpp -DCYGWIN

# Additional libraries that may be required by the linker ...
# DLIB = -lmetis  # When METIS/ParMETIS are built or installed separately from PETSc
# DLIB = C:/cygwin/packages/metis-5.0.2/build/windows/libmetis/Release/libmetis.lib

SOURCES = $(MODEL)Solver.o    \
    $(MODEL)Main.o        

all: $(SOURCES) chkopts
    -${FLINKER} $(FPPFLAGS) -o Main $(SOURCES) ${PETSC_LIB} ${DLIB}
    ${RM} $(MODEL)*.o *.mod

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

AdjuntoTamaño
Descargar main.zip1.94 MB
publicaciones de 2 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.

Thanks to the PETSc-maint.
Problem solved.
Rename the sourcefiles to use .F90 suffix and remove '-fpp' from FPPFLAGS.

Deje un comentario

Por favor inicie sesión para agregar un comentario. ¿No es socio? Únase ya