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.

UCU110
  • 413
  • 1
  • 5
  • 13
  • 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. – UCU110 May 25 '14 at 15:28
  • 1
    According to this https://groups.google.com/forum/#!msg/comp.lang.fortran/Xlyi2iRqlf8/TAWRSg2q378J the .F90 suffix should suffice. Also `_WIN64` should be OK. I don't use Windows however. – Vladimir F Героям слава May 25 '14 at 15:36
  • Hi Vladimir, Thanks, I tried `gfortran -cpp -o foo foo.F` but the problem is still there. – UCU110 May 25 '14 at 15:39
  • Do you have native compiler, or cygwin? – Vladimir F Героям слава May 25 '14 at 15:40
  • I have a native compiler. below is the compiler information. – UCU110 May 25 '14 at 15:48
  • `Using built-in specs. COLLECT_GCC=gfortran COLLECT_LTO_WRAPPER=c:/gfortran/bin/../libexec/gcc/mingw32/4.8.0/lto-wra Target: mingw32 Configured with: ../gcc-trunk/configure --prefix=/mingw --enable-languag tran,lto --with-gmp=/home/brad/gfortran/dependencies --disable-werror -- hreads --enable-nls --build=i586-pc-mingw32 --enable-libgomp --enable-sh isable-win32-registry --with-dwarf2 --disable-sjlj-exceptions --enable-l ld=mingw32 --enable-version-specific-runtime-libs Thread model: win32 gcc version 4.8.0 20130302 (experimental) [trunk revision 196403] (GCC)` – UCU110 May 25 '14 at 15:48
  • See http://stackoverflow.com/questions/4605842/how-to-identify-platform-compiler-from-preprocessor-macros – M. S. B. May 25 '14 at 17:02
  • @M.S.B. But also http://stackoverflow.com/questions/5919996/how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor – Vladimir F Героям слава May 25 '14 at 17:26

1 Answers1

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"
janneb
  • 36,249
  • 2
  • 81
  • 97