Linking Fortran and C++ code with the fortran compiler:

The difficult part is figuring out what CLIBS should be since it changes with 
C++ version and kernel.  The trick I use is to compile a short C++ program
---- hello.cpp ----
#include <iostream>
int main() {
  std::cout << "hello world!" << std::endl ;
}
--------
with g++ and the -v (for verbose flag) -- the important stuff is at the end,

randre@sunfire06$ g++ -v -o hello hello.cpp
... lots of messages ...
 /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/collect2 --eh-frame-hdr -m elf_i386 
-dynamic-linker /lib/ld-linux.so.2 -o 
hello /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/../../../crt1.o /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/../../../crti.o /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/crtbegin.o 
-L/usr/lib/gcc-lib/i386-redhat-linux/3.2.3 
-L/usr/lib/gcc-lib/i386-redhat-linux/3.2.3/../../.. /p/transpusers/randre/transp/sunfire06/tmp/ccFZJtZ6.o 
-lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s 
-lgcc /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/crtend.o /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/../../../crtn.o

this shows the libraries and object files which need to be added when linking 
a C++ program.  The actual paths depends on your machines configuration. You 
generally need
-L/usr/lib/gcc-lib/i386-redhat-linux/3.2.3 -lstdc++
as a minium.  By trial and error you can figure out whether to add -lgcc, 
-lgcc_s, crt1.o, crtbegin.o, crtn.o, ... or you can try just using the whole 
thing for CLIBS.   This is usually a pain to figure out but if we had access 
to a RHE4.0 system we could do this for you.

Also, you can not just copy object files from a RHEL3 to a RHEL4 system and 
expect them to work.  You can usually (but not always) get away with this for 
C and fortran object files but not with C++ object files.  It is best to 
start fresh when using a new kernel or compiler.

Lastly it can happen that the fortran compiler is not able to properly link 
mixed fortran/C++ code which linked ok with a previous kernel and gcc 
version.  The link line will have to be switched to use the C++ compiler and 
explicitly add the fortran libraries to the link line.

