Xref: utzoo comp.lang.fortran:3964 comp.sys.sgi:6378 Path: utzoo!attcan!uunet!wuarchive!decwrl!world!burley From: burley@world.std.com (James C Burley) Newsgroups: comp.lang.fortran,comp.sys.sgi Subject: Re: archiving block data subroutines... Message-ID: Date: 22 Oct 90 09:06:33 GMT References: <1990Oct22.033107.5159@ux1.cso.uiuc.edu> Sender: burley@world.std.com (James C Burley) Distribution: comp Organization: The World Lines: 43 In-Reply-To: jeffb@aquifer.las.uiuc.edu's message of 22 Oct 90 03:31:07 GMT In article <1990Oct22.033107.5159@ux1.cso.uiuc.edu> jeffb@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@world.std.com