How to force compilation order?

How to force compilation order?

Suppose I have a large set of routines, and I need them to compile in a certain order.

i.e . when rebuilding a project from scratch.

For example, one might have a set of Modules, and one would like to compile those first,

before compiling the routines that have the corresponding USE statements.


Hopefully, the compiler would know: if I am doing to a rebuild of the project,

that those SHOULD be done first. but I don't know if that's really the case.


If I make changes to a MODULE, does that force the recompilation of the corresponding

routines that USE it?


Another example is routines that call each other. Does it make sense to compile the Called routine first,

if one has made changes to the argument sequence? EX:


Subroutine Sub1()

call sub2 (x,y,z)


subroutine sub2(p,q,r) !  separate file in the project.

end subroutine


Now if I change the number and type of the arguments in SUB2,

it should compile that BEFORE compiling SUB1. Of course, one should make the appropriate changes to SUB1


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

The compilation order is determined for each build by scanning sources that have changed, looking for MODULE, USE and INCLUDE lines. You don't have any visibility into this process. Yes, if you make ANY changes to a module, even changing a comment, that will trigger recompilation of any source that USEs that module.

In the future, a Fortran 2008 feature called submodules will lessen the pain here, but that is still in the future.

Retired 12/31/2016

I have this problem now, see my post a few hours ago.  Module A uses module B, yet the build is not building B first, so the compilation of A fails.  Any idea how to get around this?

Usually Visual Studio is very good at this - see discussion here.

As described in there, another thing to watch out for is circular dependencies i.e., MODULE A uses MODULE B which uses C which in turn has some dependency on A/B.

I guess one obvious way is to put Modules A and B in the same file.

And put module B first.


Does Fortran allow one to set up a BATCH list,

where you can compile files in a given order?


If you did not have Visual Studio, then you would

pretty much have to use that.

You can certainly compile files from the command line in any order you want. If you are seeing incorrect orders in Visual Studio, using a current version of the product (Composer XE 2013 SP1 Update 2), please attach a ZIP of the project and sources (or provide to us via Intel Premier Support) and we'll be glad to investigate. I don't know of any open issues in this area.

Retired 12/31/2016

Leave a Comment

Please sign in to add a comment. Not a member? Join today