[Scons-users] Problem with Fortran Dependency Scanner

Damien damien at khubla.com
Mon Apr 27 12:59:37 EDT 2015


Is the mod file actually being generated somewhere in the tree?

This is what we do to set up our Fortran command line on Linux:

    env['FORTRAN'] = 'gfortran'
    env['FORTRANMODDIRPREFIX'] = '-J'
    env['FORTRANMODDIR'] = '${TARGET.dir}'
    env['FORTINCPREFIX'] = '-I'
    env['_FORTRANINCFLAGS'] = '$( ${_concat(FORTINCPREFIX, FORTRANPATH, 
INCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)'
    env['FORTRANCOM'] = '$FORTRAN -o$TARGET -c $FORTRANFLAGS 
$FORTRANMODDIRPREFIX$FORTRANMODDIR $_FORTRANINCFLAGS $SOURCES'
    env['SHFORTRANCOM'] = env['FORTRANCOM']
    env['SHF90PPCOM'] = env['FORTRANCOM']
    env['SHF95PPCOM'] = env['FORTRANCOM']
    env['F90PPCOM'] = env['FORTRANCOM']
    env['F95PPCOM'] = env['FORTRANCOM']

We had a world of pain getting Fortran modules to work, and we did this 
many years ago, with a similar blunt chainsaw on the Windows and OSX 
builds, but it works.

Damien



On 2015-04-27 10:49 AM, Nikolaus Rath wrote:
> Hi Damien,
>
> No luck:
>
> scons: Building targets ...
> gfortran -o bar.o -c -g -Wall -O3 -DSETTING
> -I/home/nikratio/tmp/scons-test/inc -J. bar.F
> bar.F:2.9:
>
>        USE com
>           1
> Fatal Error: Can't open module file 'com.mod' for reading at (1): No
> such file or directory
> scons: *** [bar.o] Error 1
>
>
> Best,
> -Nikolaus
>
>
> On 04/27/2015 08:10 AM, Damien wrote:
>> Try adding this to your flags:
>>
>> env['FORTRANMODDIRPREFIX'] = '-J'
>> env['FORTRANMODDIR'] = '${TARGET.dir}'
>>
>> Modules and directories can be a bit of a pain...
>>
>> Damien
>>
>> On 2015-04-27 8:50 AM, Nikolaus Rath wrote:
>>> Hello,
>>>
>>> I have the following tiny test project:
>>>
>>> $ find -type f
>>> ./src1/foo.f
>>> ./src1/bar.F
>>> ./src1/bar.mod
>>> ./src1/SConstruct
>>> ./src2/com.f90
>>> ./inc/params.f
>>>
>>> $ cat src1/bar.F
>>>         PROGRAM bar
>>>         USE com
>>>         IMPLICIT NONE
>>>
>>>         PRINT *, 'Starting bar'
>>>         PRINT *, 'Value of SETTING is', SETTING
>>>         call com_sub
>>>         PRINT *, 'End of bar'
>>>         END
>>>
>>> $ cat src2/com.f90
>>> MODULE com
>>>     USE foo
>>>     INTEGER:: com_int=17
>>> CONTAINS
>>>     subroutine com_sub
>>>       PRINT *, 'Starting com_sub'
>>>       CALL foo_sub
>>>       PRINT *, 'End of com_sub'
>>>     end SUBROUTINE com_sub
>>> END MODULE com
>>>
>>> $ cat src1/foo.f
>>>         MODULE foo
>>>         IMPLICIT NONE
>>>         INCLUDE 'params.f'
>>>         INTEGER foo_int
>>>
>>>         CONTAINS
>>>
>>>         subroutine foo_sub
>>>         PRINT *, 'In foo_sub'
>>>         end SUBROUTINE
>>>         END MODULE foo
>>>
>>> $ cat inc/params.f
>>>         real,parameter::zero=0,one=1
>>>
>>>
>>> I'm trying to build it with the following Scons script:
>>>
>>> $ cat src1/SConstruct
>>> # Attention, emacs, this is a -*- python -*- file.
>>> import os
>>>
>>> opts = Variables(None, ARGUMENTS)
>>> opts.Add(BoolVariable('DEBUG', 'Enable debugging', False))
>>> opts.Add(BoolVariable('SETTING', 'Enable setting', True))
>>>
>>> env = DefaultEnvironment(variables = opts,
>>>                            ENV = {'PATH' : os.environ['PATH']})
>>>
>>> # Use the same settings for all Fortran dialects
>>> for dialect in ('F77', 'F90', 'F95', 'F03'):
>>>       for var_suffix in ('', 'FLAGS', 'PATH'):
>>>           env['%s%s' % (dialect, var_suffix)] = \
>>>               '${FORTRAN%s}' % var_suffix
>>>
>>> opts = Split('-g -Wall')
>>> if env['DEBUG']:
>>>       opts += Split('-O0 -g')
>>> else:
>>>       opts += Split('-O3')
>>> env.Append(FORTRANFLAGS=opts, CPPDEFINES=['SETTING'],
>>>              FORTRANPATH=['#/../inc'])
>>>
>>> sources = [ 'bar.F',
>>>               'foo.f',
>>>               '../src2/com.f90' ]
>>>
>>> # Object method returns both .mod and .o, so we filter for the latter.
>>> objects = [ x for x in Object(sources) if x.get_suffix() == '.o' ]
>>> Program('test', objects)
>>>
>>>
>>> However, this fails with:
>>>
>>> $ scons
>>> scons: Reading SConscript files ...
>>> scons: done reading SConscript files.
>>> scons: Building targets ...
>>> gfortran -o /home/nikratio/tmp/scons-test/src2/com.o -c -g -Wall -O3
>>> -I/home/nikratio/tmp/scons-test/inc
>>> /home/nikratio/tmp/scons-test/src2/com.f90
>>> /home/nikratio/tmp/scons-test/src2/com.f90:2.6:
>>>
>>>     USE foo
>>>         1
>>> Fatal Error: Can't open module file 'foo.mod' for reading at (1): No
>>> such file or directory
>>> scons: *** [/home/nikratio/tmp/scons-test/src2/com.o] Error 1
>>> scons: building terminated because of errors.
>>>
>>>
>>> It seems that Scons did not notice that src2/com.f90 depends on src1/foo.f.
>>>
>>>
>>> Why is that?
>>>
>>>
>>> With experimenting, I found out that it helps if I add '.' to
>>> FORTRANPATH - but that seems wrong, because I don't want to include any
>>> files from src1/.
>>>
>>>
>>> Best,
>>> -Nikolaus
>>>
>> _______________________________________________
>> Scons-users mailing list
>> Scons-users at scons.org
>> https://pairlist4.pair.net/mailman/listinfo/scons-users
>>
>



More information about the Scons-users mailing list