From: (Gerhard Schneider) Subject: COFF, the linker and Fortran BLOCK DATA Organization: Kaleida Labs, Inc. Sender: root AT ilfb03 DOT tuwien DOT ac DOT at Originator: daemon AT talisman DOT kaleida DOT com Date: 19 Jan 94 12:28:19 GMT To: djgpp AT sun DOT soe DOT clarkson DOT edu Reply-To: djgpp AT sun DOT soe DOT clarkson DOT edu With the change of djgpp from a.out to COFF we got problems with the following code structure (the easiest sample code follows): If you convert a fortran BLOCK DATA statement into C-Code (f2c) and put the compiled code into a library the linker ignores it. Sample: ---- makefile ---- all: f2c -a -h -r test1.f f2c -a -h -r test2.f gcc -c test1.c gcc -c test2.c ar ruv libtest.a test2.o ranlib libtest.a gcc -o test1 test1.o test2.o -lf77 -li77 -lm gcc -o test2 test1.o -L. -ltest -lf77 -li77 -lm coff2exe test1 coff2exe test2 test1.exe test2.exe ---- test1.f ---- PROGRAM TEST1 C COMMON /COMM1/ A C PRINT *,A C END ---- test2.f ---- BLOCK DATA C COMMON /COMM1/ A C DATA A /1/ C END ---- test1.c ---- /* test1.f -- translated by f2c (version of 21 October 1993 13:46:10). You must link the resulting object file with the libraries: -lf77 -li77 -lm (in that order) */ #include "f2c.h" /* Common Block Declarations */ struct { real a; } comm1_; #define comm1_1 comm1_ /* Table of constant values */ static integer c__4 = 4; static integer c__1 = 1; /* Main program */ MAIN__() { /* Builtin functions */ integer s_wsle(), do_lio(), e_wsle(); /* Fortran I/O blocks */ static cilist io___1 = { 0, 6, 0, 0, 0 }; s_wsle(&io___1); do_lio(&c__4, &c__1, (char *)&comm1_1.a, (ftnlen)sizeof(real)); e_wsle(); } /* MAIN__ */ /* Main program alias */ int test1_ () { MAIN__ (); } ---- test2.c ---- /* test2.f -- translated by f2c (version of 21 October 1993 13:46:10). You must link the resulting object file with the libraries: -lf77 -li77 -lm (in that order) */ #include "f2c.h" /* Common Block Declarations */ struct comm1_1_ { real a; }; #define comm1_1 (*(struct comm1_1_ *) &comm1_) /* Initialized data */ struct { real e_1; } comm1_ = { (float)1. }; ---- END ---- Thank you for your help Gerhard Schneider -- Gerhard Schneider e-Mail: gs AT ilfb03 DOT tuwien DOT ac DOT at Institute of Light Weight Structures (E317) Tel.: +43 1 58801 3711 Technical University of Vienna / Austria Fax: +43 1 505 44 68 A-1040 Wien, Gusshausstrasse 27-29