Compiling empty fortran files

Compiling empty fortran files

After preprocessing it can happen that some source files in our project are completely empty. Some compilers, such as gcc, accept this input and produce an essentially empty object file. This is the behavior we want. However, ifort (9.0) gives an error message (see below). Is there any way to make ifort accept the empty input file, which would allow us to continue using our very simple build system? An alternative is to include stub subroutines in the files, but that is not very clean.

Ulf Ekstrom,
VU University Amsterdam

Error message from trying to compile an empty file:
ifort -c empty.F
fortcom: Error: empty.F, line 3: Syntax error, found END-OF-FILE when expecting one of: ; BLOCK BLOCKDATA PROGRAM TYPE COMPLEX BYTE CHARACTER ...

compilation aborted for empty.F (code 1)

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

The handling of this changed beginning with our 9.1.040 release, where empty source files no longer produce the error you received.

My example test.F contains a single blank line.

$ ifort -V -c test.F

Intel Fortran Compiler for 32-bit applications, Version 9.1 Build 20061103Z Package ID: l_fc_c_9.1.040

Copyright (C) 1985-2006 Intel Corporation. All rights reserved.

Intel Fortran 9.1-6470

The easiest resolution is to upgrade to at least 9.1.040.

To use compilers prior to 9.1.040, you will need to provide some form of stub subprogram. Or perhaps another alternative, if your source file is empty or contains less than two lines (which would account for a SUBROUTINE/FUNCTION plus END statements), is to condition the actual compilation in your simple build system based on checking the number of lines in the source file.

Thank you for the reply. Since our users typically compile the software themselves we have to support versions < 9.1. I will try your second alternative, but it is not completely trivial since the source files are not "empty" until after preprocessing, and then the file contain macro definitions and comments. Anyway, now I know what the status is. Thanks again.

Ulf Ekstrom
VU University Amsterdam

Login to leave a comment.