A fortran main program and a fortran shared library dlopen'ed from the main program use the same unit number to report results to two different files (explicitely opened in the main program and in the library, see example below)
With GCC 3.x when one links with libg2c.a to produce the shared library (i.e. g77 -shared -fPIC -Wl,-Bsymbolic -o libtest.so test.f /usr/lib64/libg2c.a ) output goes to the two files as intended. With gfortran 4.0.2 and also snapshot 4.1.0 20051022 the attempt to write to the file in the shared library fails with Fortran runtime error: End of record In this case I have used gfortran -fPIC -shared -Wl,-Bsymbolic -o libtest.so test.f /usr/lib64/libgfortran.a gcc -c testx.c gfortran main.f testx.o -ldl to produce the executable and the shared library. When the shared library is built without libgfortran.a, once unit 1 is opened in the shared library, all output goes to this file, not the file connected to unit 1 in the main program. I'm not sure if this is a bug or intended behavior. c----------------------- test.f subroutine test open(1,file='junk_shared') write(1,*) 'In subroutine test' return end /*----------------- testx.c #include <dlfcn.h> #include <stdio.h> typedef void (*MyFunc)(); void testx_() { void *h; MyFunc func; h = dlopen("./libtest.so",RTLD_LAZY); if( !h ) { printf("Failed to open libtest: %s\n",dlerror()); return; } func = (MyFunc) dlsym(h,"test_"); if( !func ) { printf("Failed to resolve test: %s\n",dlerror()); return; } func(); } c-------------- main.f program io_test open(1,file='junk_main') write(1,*) 'In main program, calling testx' call testx write(1,*) 'Back in main program after call to testx: ' end -- Summary: Fortran I/O to same unit number in main program and in a shared library Product: gcc Version: 4.0.2 Status: UNCONFIRMED Severity: normal Priority: P2 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: iwan at irs dot phy dot nrc dot ca GCC build triplet: x86_64-unknown-linux-gnu GCC host triplet: x86_64-unknown-linux-gnu GCC target triplet: x86_64-unknown-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24576