Login | Register
My pages Projects Community openCollabNet

Discussions > SCons User General Discussions (OBSOLETE) > FORTRAN build order incorrect

Project highlights:

24 Aug 2014: Release 2.3.3 is now available at the download page.

05 July 2014: Release 2.3.2 is now available at the download page.

02 Feb 2013: Release 2.3.0 is now available at the download page.

scons
Discussion topic

Back to topic list

FORTRAN build order incorrect

Author pbauman
Full name Paul Bauman
Date 2008-09-30 10:18:56 PDT
Message Hello,

I've pulled this problem from a much larger code base to a simple test
case. Assume a ./src directory exists and the following two source files
are contained within it.

test.F90:
program main
  use test
  implicit none
  test_char = "Hello, World!"
  write(*,*) trim(test_char)
end program main

test_mod.F90:
module test
  implicit none
  character(len=256) :: test_char
end module test

Then the following SConstruct breaks:

import os
env = DefaultEnvironment( ENV = os.environ )
env = env.Clone( tools = [ 'gfortran ] )
env = env.Clone( F90FLAGS = '-g' )

#env = env.Clone( FORTRANMODDIR = '#/mods' , FORTRANMODDIRPREFIX = '-M ' )

src1 = '#/src/test.F90'
src2 = '#/src/test_mod.F90'

env.Program( 'test', [ src2, src1 ] )
#env.Program( 'test', ['#/test.F90', '#/test_mod.F90'] )

What happens is that it tries to build test.F90 before test_mod.F90.
Since the module hasn't been built yet, the build fails.

bash-3.2$
bash-3.2$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
gfortran -o src/test.o -c -g src/test.F90
src/test.F90:3.10:

  use test
         1
Fatal Error: Can't open module file 'test.mod' for reading at (1): No
such file or directory
scons: *** [src/test.o] Error 1
scons: building terminated because of errors.
bash-3.2$

There are two solutions that I don't understand and I was hoping for
some clarification.

First, if the line specifiying the FORTRANMODDIR is uncommented, then
scons figures out the right order:

bash-3.2$
bash-3.2$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
gfortran -o src/test_mod.o -c -g -M mods src/test_mod.F90
gfortran -o src/test.o -c -g -M mods src/test.F90
gfortran -o test.exe src/test_mod.o src/test.o
scons: done building targets.
bash-3.2$
bash-3.2$
bash-3.2$

This seemed strange to me because I thought that it would just specify
the command line options and not effect the scanner.

The second alternative is to create an SConscript in the directory that
processes the objects and returns them to the SConstruct so that the
'src/' is not in the source name. I achieve this in this simple example
by merely copying the SConstruct to the same directory as the files and
using the second 'Program' statement instead of the first (and I again
commented out the FORTRANMODDIR statement). Then, again, scons figures
out the right order.

bash-3.2$
bash-3.2$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
gfortran -o test_mod.o -c -g test_mod.F90
gfortran -o test.o -c -g test.F90
gfortran -o test.exe test.o test_mod.o
scons: done building targets.
bash-3.2$

The other reason I'm curious whether this is a bug or not because on my
much larger code base, the '-module' statement actually breaks the
scanner. I'm still trying to work that down to the simple example
though. Any comments are most appreciated. Sorry for the long email,
just trying to be as detailed as possible.

Thanks,

Paul

« Previous message in topic | 1 of 17 | Next message in topic »

Messages

Show all messages in topic

FORTRAN build order incorrect pbauman Paul Bauman 2008-09-30 10:18:56 PDT
     Re: [scons-users] FORTRAN build order incorrect cournape David Cournapeau 2008-09-30 19:39:46 PDT
         Re: [scons-users] FORTRAN build order incorrect David Cournapeau <cournape at gmail dot com> David Cournapeau <cournape at gmail dot com> 2008-09-30 21:26:24 PDT
         Re: [scons-users] FORTRAN build order incorrect pbauman Paul Bauman 2008-10-02 10:53:25 PDT
             Re: [scons-users] FORTRAN build order incorrect cournape David Cournapeau 2008-10-02 22:08:43 PDT
                 Re: [scons-users] FORTRAN build order incorrect pbauman Paul Bauman 2008-10-03 06:46:57 PDT
                     Re: [scons-users] FORTRAN build order incorrect sjoerd Sjoerd de Ridder 2008-10-03 13:09:43 PDT
                         Re: [scons-users] FORTRAN build order incorrect pbauman Paul Bauman 2008-10-03 14:26:07 PDT
                             Re: [scons-users] FORTRAN build order incorrect sjoerd Sjoerd de Ridder 2008-10-03 23:02:34 PDT
                                 Re: [scons-users] FORTRAN build order incorrect gregnoel Greg Noel 2008-10-04 03:17:16 PDT
                                 Re: [scons-users] FORTRAN build order incorrect cournape David Cournapeau 2008-10-04 22:16:58 PDT
                                     Re: [scons-users] FORTRAN build order incorrect miles1981 Matthieu Brucher 2008-10-05 00:14:35 PDT
                                         Re: [scons-users] FORTRAN build order incorrect sjoerd Sjoerd de Ridder 2008-10-05 15:51:09 PDT
                                             Re: [scons-users] FORTRAN build order incorrect David Cournapeau <cournape at gmail dot com> David Cournapeau <cournape at gmail dot com> 2008-10-05 18:12:37 PDT
                                             Re: [scons-users] FORTRAN build order incorrect gregnoel Greg Noel 2008-10-05 22:26:10 PDT
                                                 Re: [scons-users] FORTRAN build order incorrect sjoerd Sjoerd de Ridder 2008-10-06 00:37:38 PDT
                                                     Re: [scons-users] FORTRAN build order incorrect cournape David Cournapeau 2008-10-06 21:06:04 PDT
Messages per page: