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.



Result 1:

Hello World

Solved in WINDOWS

Result 2:

Hello World


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


program Main

    use Solver    
    implicit none

    ! Variables

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

end program Main


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>

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

end Module Solver


# 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


# 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    \

all: $(SOURCES) chkopts
    ${RM} $(MODEL)*.o *.mod


Downloadapplication/zip main.zip1.94 MB
2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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

Leave a Comment

Please sign in to add a comment. Not a member? Join today