Mixed linking

I’m trying to link some Gfortran 4.3.3 code into PGI 7.2.5. The system I’m programming on recommends static linking. Linking in the 433 Gfortran library works, but the code dies at runtime. The errors I got made me suspect that somehow the GNU Fortran library was unable to interface properly with the operating system (allocate/print/write didn’t work).

Either way, I’ve found that if I build with -Bstatic_pgi (which leaves non-PGI libraries dynamic) the gfortran library works.

I still need to link quite a few other libraries statically, but is there any command line argument to specify that just the Gfortran library be dynamically linked, and everything else be linked statically?

That is my main question, and I really do not need the problems described in the first paragraph resolved. I’m trying to use the GNU compiler because I’m more familiar with its command line arguments. PGI seems to do fast or faster optimizations, and I’m not necessarily trying to get peak from the compiler in these tests (strange request – I apologize).

Ben

Hi Ben,

What language is your code written in, F77 or F90?

Mixing F90 objects from different compilers can be problematic. Each F90 compiler has different representations for modules and descriptors, have different padding, alignment, and I/O. In other words, you should try an use the same compiler for F90 builds.

To answer your specific question, since order is preserved on the link line, you can bracket the libraries you wish to have dynamically linked between the “-Bdynamic” and “-Bstatic” flags. For example:

% pgf90 -o test.out a.o -dryrun -Bdynamic -lgfortran -Bstatic
...
/usr/local/bin/ld /usr/lib64/crt1.o /usr/lib64/crti.o /usr/pgi/linux86-64/dev/lib/trace_init.o /usr/lib64/gcc/x86_64-suse-linux/4.1.2/crtbeginT.o /usr/pgi/linux86-64/dev/lib/f90main.o -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/pgi/linux86-64/dev/lib/pgi.ld -L/usr/pgi/linux86-64/dev/lib -L/usr/lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2 a.o -Bdynamic -lgfortran -Bstatic -rpath /usr/pgi/linux86-64/dev/lib -o test.out -lpgf90 -lpgf90_rpm1 -lpgf902 -lpgf90rtl -lpgftnrtl -lnspgc -lpgc -lrt -lpthread -lm -lgcc -lgcc_eh -lc -lgcc -lgcc_eh -lc /usr/lib64/gcc/x86_64-suse-linux/4.1.2/crtend.o /usr/lib64/crtn.o

Hope this helps,
Mat