3.1.14. Mixed Language Programming (About Object Compatibility)

This section describes notes on compatibility and linking of Fotran, C (trad/clang) and C++ (trad/clang) objects generated by Fujitsu compiler.

For details about mixed language programming, refer to the following documentation:

Fortran User’s Guide
Chapter 11 Mixed Language Programming
Chapter 12 Multiprocessing
C User’s Guide
Chapter 4 Multiprocessing
Chapter 7 Notes on Interlanguage Linkage
9.6 Notes on Interlanguage Linkage
C++ User’s Guide
Chapter 4 Multiprocessing
Chapter 7 Notes on Interlanguage Linkage
9.6 Notes on Interlanguage Linkage and Linkage with trad mode’s Objects
Profiler User’s Guide

5.1.6 Mixed Language Programming for MPI Program

3.1.14.1. Object Compatibility

The following objects can be linked to each other:

  • Objects generated in Fortran

  • Objects generated in trad mode of C

  • Objects generated in clang mode of C

  • Any one of Objects of C++

3.1.14.2. Objects of C++

Objects of C++ can only be linked by objects using the same STL.

The used STL is divided into three categories. You cannot mix these objects.

  • Objects generated in trad mode of C++

  • Objects generated in clang mode of C++ using libc++ for STL

  • Objects generated in clang mode of C++ using libstdc++ for STL

3.1.14.3. Mixed Language Programming

Refer to manuals “Fortran User’s Guide”, “C User’s Guide” and “C++ User’s Guide”.

Describes only compile commands when linking here.

On mixed language programming, the compile commands and required options you use when linking depend on the language to mix.

The following table shows the combinations when using a cross compiler. If you use a native compiler, replace the frtpx/fccpx/FCCpx commands with frt/fcc/FCC commands, respectively. If you use MPI, replace them with the commands for MPI.

Compile command to use when linking

Fortran object

C object

C++ object

Fortran

frtpx

frtpx

  • When the C++ object file is generated in trad mode
    frtpx --linkstl=libfjc++
  • When using libc++ for STL and generating C++ objects in clang mode
    frtpx --linkstl=libc++
  • When using libstdc++ for STL and generating C++ objects in clang mode
    frtpx --linkstl=libstdc++

C

fccpx --linkfortran

fccpx

Not supported. Use FCCpx.

C++

FCCpx --linkfortran

FCCpx

FCCpx

Shows linking examples below.

Linking Fortran and C objects using Fortran when linking:

frtpx -c fortmain.f95
fccpx -c cfunc.c
frtpx -o a.out fortmain.o cfunc.o

Linking Fortran and C objects using Fortran when linking (When C is main):

frtpx -c fortsub.f95
fccpx -c cmain.c
frtpx -mlcmain=main -o a.out cmain.o fortsub.o

Linking Fortran and C objects using C when linking:

frtpx -c fortmain.f95
fccpx -c cfunc.c
fccpx --linkfortran -o a.out fortmain.o cfunc.o

Linking Fortran and C objects using C when linking (When C is main):

frtpx -c fortsub.f95
fccpx -c cmain.c
fccpx --linkfortran -o a.out cmain.o fortsub.o

Linking Fortran and C++ objects generated in trad mode using Fortran when linking:

frtpx -c fortmain.f95
FCCpx -c cppfunc.cc
frtpx --linkstl=libfjc++ -o a.out fortmain.o cppfunc.o

Linking Fortran and C++ objects generated in trad mode using Fortran when linking (When C++ is main):

frtpx -c fortsub.f95
FCCpx -c cppmain.cc
frtpx -mlcmain=main --linkstl=libfjc++ -o a.out cppmain.o fortsub.o

Linking Fortran and C++ objects generated in clang mode with -stdlib=libc++ option using Fortran when linking:

frtpx -c fortmain.f95
FCCpx -Nclang -stdlib=libc++ -c cppfunc.cc
frtpx --linkstl=libc++ -o a.out fortmain.o cppfunc.o

Linking Fortran and C++ objects generated in clang mode with -stdlib=libstdc++ option using Fortran when linking:

frtpx -c fortmain.f95
FCCpx -Nclang -c cppfunc.cc
frtpx --linkstl=libstdc++ -o a.out fortmain.o cppfunc.o

libstdc++ is the STL used by default in clang mode for the C++ compiler.

Linking Fortran and C++ objects generated in trad mode using C++ when linking:

frtpx -c fortmain.f95
FCCpx -c cppfunc.cc
FCCpx --linkfortran -o a.out fortmain.o cppfunc.o

Linking Fortran and C++ objects generated in trad mode using C++ when linking (When C++ is main):

frtpx -c fortsub.f95
FCCpx -c cppmain.cc
FCCpx --linkfortran -o a.out cppmain.o fortsub.o

Linking Fortran and C++ objects generated in clang mode with -stdlib=libc++ option using C++ when linking:

frtpx -c fortmain.f95
FCCpx -Nclang -stdlib=libc++ -c cppfunc.cc
FCCpx -Nclang -stdlib=libc++ --linkfortran -o a.out fortmain.o cppfunc.o

Linking Fortran and C++ objects generated in clang mode with -stdlib=libstdc++ option using C++ when linking:

frtpx -c fortmain.f95
FCCpx -Nclang -c cppfunc.cc
FCCpx -Nclang --linkfortran -o a.out fortmain.o cppfunc.o

libstdc++ is the STL used by default in clang mode for the C++ compiler.

Linking C and C++ objects generated in trad mode using C++ when linking:

fccpx -c cmain.c
FCCpx -c cppfunc.cc
FCCpx -o a.out cmain.o cppfunc.o

Linking C and C++ objects generated in clang mode with -stdlib=libc++ option using C++ when linking:

fccpx -c cmain.c
FCCpx -Nclang -stdlib=libc++ -c cppfunc.cc
FCCpx -Nclang -stdlib=libc++ -o a.out cmain.o cppfunc.o

Linking C and C++ objects generated in clang mode with -stdlib=libstdc++ option using C++ when linking:

fccpx -c cmain.c
FCCpx -Nclang -c cppfunc.cc
FCCpx -Nclang -o a.out cmain.o cppfunc.o

libstdc++ is the STL used by default in clang mode for the C++ compiler.

3.1.14.4. Mixed Language Programming for MPI

On mixed language programming of MPI, specify the following options when linking. Links libraries required when using the profiler.

Command for linkage

Options that must be specified

mpifccpx command(mpifcc command for native compiler)
mpiFCCpx command(mpiFCC command for native compiler)

-lfjprofmpif option

mpifrtpx command(mpifrt command for native compiler)

-lfjprofmpi option

Example:

mpifrtpx -o a.out fortmain.o cfunc.o -lfjprofmpi
mpifccpx --linkfortran -o a.out fortmain.o cfunc.o -lfjprofmpif

3.1.14.5. Object Compatibility of Fujitsu Compiler and Other Compiler

Refer to “Compatibility Between Objects Generated by Fujitsu Compiler and Those by Other Compilers” in “Programming Guide (Programming common part)“.