next up previous contents
Next: 12 Using Shared Libraries Up: IMPL_repdoc Previous: 10 Performance   Contents

Subsections

11 Linking C++ and F90

Linking F90 with C++ can be challenging. Linking C++ with anything can be challenging. However, it is possible, though there is no generic method that works on all platforms. Many of the platforms have problems with the entry point, since traditionally the F90 entry is MAIN_, where the C++ entry is main. However, using link flags these difficulties can be overcome. On some platforms there is no problem. Template instantiation can be a problem, and the difficulties are directly proportional to how smart the C++ compiler tries to be. Most of these overzealous compilers can be told to relax via compiler flags. In general F90 is more well behaved, and this helps. On all the compilers we used, the other language's standard libraries were not found. This problem can be solved by running the opposite compiler in verbose mode (-v on many platforms). It then shows its ld line, and the libraries may be ascertained.

11.1 SunOS

The sun MPI compilers are /optSUNWhpc/bin/[mpf90, mpCC, mpcc]. We have found it easiest to link on this platform using mpCC. This C++ compiler will not link F90 code immediately. However, when passed the correct libraries it becomes satisfied. They were:

-lfui -lfai -lfai2 -lfsumai -lfprodai -lfminlai -lfmaxlai -lfminvai -lfmaxvai
  -lfsu -lsunmath -lm -lc
It was quite important on this platform to turn off the C++ compiler's ``smart'' templates. This feature tries to gather instances of templates at link time, and prevents linking from occurring. To do this, the compiler requires the flag '-instantiate=static', which tells it to act like the original C++ compilers and just put the instances of a template used into each object file.

11.2 AIX

The IBM compilers (suprisingly) adapt to linking C++ and F90 quite easily. We used the C++ compiler and merely had to send it the F90 libraries. These were:

-L/usr/lpp/ppe.poe/lib/threads -L/usr/lpp/ppe.poe/lib
-L/usr/lpp/ppe.poe/lib/ip,-L/lib/threads -lmpi_r -lvtd_r -lxlf90 -lxlopt -lxlf
-lxlomp_ser -lpthreads -lm_r -lm -lc_r -lc /usr/lpp/ppe.poe/lib/libc.a

11.3 IRIX

Irix C++ has the same officiousness as does the Sun compiler. Its attempt at being clever with C++ templates can be stopped easily by sending the -no_prelink -ptused flags, which tell the compiler not to pre-link, and instantiate all templates that are referenced.

11.4 Linux

The linux configuration of g++ and pgf90 worked together quite well. The linker used was pgf90, and the only C++ library that had to be added to the link line was -lstdc++.


next up previous contents
Next: 12 Using Shared Libraries Up: IMPL_repdoc Previous: 10 Performance   Contents
esmf_support@list.woc.noaa.gov