Topic: Missing C header files in mixed Fortran and C project

I am moving a mixed Fortran 77 and C program from Linux (gfortran and cc) to Windows (27 .f files and 18 .c files).  Sixteen of the C files include a common header file which contains almost 2 dozen C headers.  However, 3 headers are not found which is the only compilation error.  They are

#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/wait.h>

My assumption is that there is no corresponding Windows equivalent.  If I comment out the 3 headers, the program compiles without error but does not work properly.  So apparently there is something in 1 or more of the 3 headers that is required but otherwise not flagged during compilation.  I am not the original author.  Any help with this issue is appreciated.


BTW, This is my first Simply Fortran project so this may be a noob error.

Re: Missing C header files in mixed Fortran and C project

Those headers are related to the POSIX API, so, no, they aren't available in Windows.  However, because your project did actually compile, it would appear that they're also unnecessary.  The compilation would have failed if those headers had contained a constant, structure, or API call that your program used on Windows.

Your program not working is a different matter.  It could be all sorts of issues.  Do you receive any warnings during the build?  What exactly do you mean by "does not work properly?" 

Often times with Fortran code that is somewhat older, there may have been assumptions when writing the code about how Fortran works that are incorrect.  For example, a common assumption in older code is that all variables initialize to zero, which definitely is not the case.  On Linux, though, a compiler flag might have been set to actually enable this behavior (-finit-local-zero).  Do you have a Makefile with this code that you could check for some additional compiler flags?  You may have to enter those into Project Options in Simply Fortran as well.

Jeff Armstrong
Approximatrix, LLC

Re: Missing C header files in mixed Fortran and C project

There were no warnings other than the missing headers.  Since I commented them out, apparently some variables ended up with some value other than what was needed from those headers and did not cause a compilation error.  The program unpacks a file in an internationally used meteorological binary format known as BUFR.  By not working, the program errors with a message that the file is not a BUFR file.  There was no Linux makefile.  In Linux each C or F77 file was compiled with minor command line switches:

gcc -DUNDERSCORE -DLINUX -c <filename.c>
gfortran -fno-second-underscore -c <filename.f>

Finally, the main F77 file was compiled with:

gfortran -fno-second-underscore -o decodebufr decodebufr.f *.o

Googling seems to indicate a relationship/dependence between sys/ipc.h and sys/msg.h.  So it seems like I'm going to have to try to identify the variable(s) and what value(s) are expected.  Ugh!

Re: Missing C header files in mixed Fortran and C project

The header files you're unable to include are normally used for external process control and interprocess communication (See Wikipedia).  I wouldn't think it would be necessary to decode a file.  Furthermore, if a constant were used from those files, the compiler would have failed because it would have hit an "undefined" value somewhere along the way.  There's a possibility, though, that a constant in one of those files is the same as something the Windows API provides such that there isn't a compilation error, but that seems unlikely.

If the program compiles, I think your best bet would be to debug it to determine why exactly it reports it is not a BUFR file.  Just some quick googling suggest that an NOAA codebase with a file named decodebufr.f relies on certain environment variables to locate files.  Do you know if that error message is printed if it can't find a file? It could be so generic that, if it cannot find a file because an environment variable is set up, it just reports that it isn't a BUFR file rather than saying the file doesn't exist.

Jeff Armstrong
Approximatrix, LLC