archiving block data subroutines...

James C Burley burley at world.std.com
Mon Oct 22 19:06:33 AEST 1990


In article <1990Oct22.033107.5159 at ux1.cso.uiuc.edu> jeffb at aquifer.las.uiuc.edu (Jeffrey Biesiadecki) writes:

   Hi -

   We have a library written in Fortran77 which includes a block data
   subroutine.  If we use "ar" to archive the object files of the library,
   and then try to compile a program using the resulting "lib???.a" file,
   everything works fine EXCEPT the block data subroutine is never executed
   (that is, the initializations are not made).  If the block data object file
   is linked in explicitly with the fortran compiler, then the initializations
   are done.

Hi back!  I know nothing about "ar" or "lib???.a" files.  But in Fortran,
there is a specification for forcing the inclusion of a BLOCK DATA program
unit in a program.  It is EXTERNAL, believe it or not.  For example:

      PROGRAM FOO
      EXTERNAL BDATA
      COMMON /X/I
      PRINT *,I
      END

      BLOCK DATA BDATA
      COMMON /X/I
      DATA I/5/
      END

Without "EXTERNAL BDATA", the block data program unit must be explicitly
linked with the program, or whatever wording to that affect is appropriate
(since the standard doesn't really talk about linking).  With it, the linker
should complain if it can't find a block data program unit named BDATA when
linking FOO, and thus should also pull it in from any library it is
searching.

Give this approach a try.  I realize it requires you to modify the code
using the block data program  unit, but that might be a good idea anyway, to
improve its portability.  However, be aware that some nonconforming
implementations of Fortran might do the wrong thing, like assume BDATA must
be a subroutine or function but NOT a block data program unit, so try testing
this approach using, say, the example above (i.e. put BDATA in a library using
"ar" and link it to FOO after compiling both).

James Craig Burley, Software Craftsperson    burley at world.std.com



More information about the Comp.sys.sgi mailing list