2

Dear All I have a small Fortran program containing preprocessor macro. Below is a minimal example. On mac os x, it works well but when I compile it on windows 7 (64-bit) it always prints unknown operating system. I am using gfortran-4.8.0 (mingw32) on windows 7.

      program foo
      implicit integer(i-n), double precision (a-h,o-p),
     + character*8(x-z)
*
#ifdef _WIN64
      zterm = 'wxt'
#elif _WIN32
      zterm = 'wxt'
#elif __APPLE__
      zterm = 'aqua'
#elif __linux
      zterm = 'x11'
#elif __unix
      zterm = 'x11'
#elif __posix
      zterm = 'x11'
#else
      print*, 'unknown operating system'
#endif
      end program foo

Changing #ifdef _WIN64 to #if defined (_WIN64) did not help. Any suggestion will be appreciated.

8
  • On Mac I don't pass any flag to the compiler. Just normal gfortran -o foo foo.F and it works fine. So I did the same on windows, but there it does not work. Commented May 25, 2014 at 15:28
  • 1
    According to this groups.google.com/forum/#!msg/comp.lang.fortran/Xlyi2iRqlf8/… the .F90 suffix should suffice. Also _WIN64 should be OK. I don't use Windows however. Commented May 25, 2014 at 15:36
  • Hi Vladimir, Thanks, I tried gfortran -cpp -o foo foo.F but the problem is still there. Commented May 25, 2014 at 15:39
  • Do you have native compiler, or cygwin? Commented May 25, 2014 at 15:40
  • I have a native compiler. below is the compiler information. Commented May 25, 2014 at 15:48

1 Answer 1

4

This might be GFortran PR 42954. Since GFortran started using libcpp instead of running cpp in a separate process, many of these built-in macros are missing.

As a workaround, you can as part of your build process generate a file with these builtin macro definitions which you can then include. E.g. have a make target which runs

gcc -E -dM - < /dev/null > builtins.inc

Then your sources should depend on builtins.inc in the Makefile, and in the beginning of your source files you

#include "builtins.inc"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.