Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Fortran Preprocessor Definition Failed in Makefile

danielsue
Beginner
1,401 Views

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

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



0 Kudos
4 Replies
mecej4
Honored Contributor III
1,401 Views
I see only a part of the picture, but it strikes me that the use of $(FPPFLAGS) in the linker command line is neither required nor has any effect. Rather, -fpp and -DCYGWIN have to be used at the time that the .o files are being produced by compiling the sources. What are the implicit rules, in your setup, that are in effect for producing .o files from the sources?
0 Kudos
danielsue
Beginner
1,401 Views
mecej4 wrote:

I see only a part of the picture, but it strikes me that the use of $(FPPFLAGS) in the linker command line is neither required nor has any effect. Rather, -fpp and -DCYGWIN have to be used at the time that the .o files are being produced by compiling the sources. What are the implicit rules, in your setup, that are in effect for producing .o files from the sources?

Thanks for your quick reply. I use makefile to build the project, as follows: -------------------- include ${PETSC_DIR}/conf/variables include ${PETSC_DIR}/conf/rules MODEL =../Main/ FPPFLAGS = -fpp -DCYGWIN SOURCES = $(MODEL)Solver.o \ $(MODEL)Main.o all: $(SOURCES) chkopts -${FLINKER} $(FPPFLAGS) -o Main $(SOURCES) ${PETSC_LIB} ${DLIB} ${RM} $(MODEL)*.o *.mod -------------------- The problem is: $(FPPFLAGS) does not take effect in the makefile.
0 Kudos
danielsue
Beginner
1,401 Views
Thanks to the PETSc-maint. Problem solved. Rename the sourcefiles to use .F90 suffix and remove '-fpp' from FPPFLAGS.
0 Kudos
danielsue
Beginner
1,401 Views

Thanks to you all.

0 Kudos
Reply