Problems compiling or linking Fortran programs


Up: In Case of Trouble Next: General Previous: General



Up: In Case of Trouble Next: General Previous: General


General


Up: Problems compiling or linking Fortran programs Next: Problems Linking C Programs Previous: Problems compiling or linking Fortran programs

    1. Q: When linking the test program, the following message is generated:


     f77 -g -o secondf secondf.o -L/usr/local/mpich/lib -lmpich 
     invalid option -L/usr/local/mpich/lib 
     ld: -lmpich: No such file or directory 
    

    A: This f77 program does not accept the -L command to set the library search path. Some systems provide a shell script for f77 that is very limited in its abilities. To work around this, use the full library path instead of the -L option:
     f77 -g -o secondf secondf.o /usr/local/mpich/lib/libmpich.a 
    
    As of the mpich 1.2.0 release, the mpich configure attempts to find the correct option for indicating library paths to the Fortran compiler. If you find that the mpich configure has made an error, please submit a bug report to [email protected].


    2. Q: When linking Fortran programs, I get undefined symbols such as

     f77  -c secondf.f 
     secondf.f: 
      MAIN main: 
     f77  -o secondf secondf.o -L/home/mpich/lib/solaris/ch_shmem -lmpich  
     Undefined                       first referenced 
      symbol                             in file 
     getdomainname                       
     /home/mpich/lib/solaris/ch_shmem/libmpi .a(shmempriv.o) 
     ld: fatal: Symbol referencing errors. No output written to secondf 
    
    There is no problem with C programs.


    A: This means that your C compiler is providing libraries for you that your Fortran compiler is not providing. Find the option for the C compiler and for the Fortran compilers that indicate which library files are being used (alternately, you may find an option such as -dryrun that shows what commands are being used by the compiler). Build a simple C and Fortran program and compare the libraries used (usually on the ld command line). Try the ones that are present for the C compiler and missing for the Fortran compiler. Mpich attempts to determine these libraries for you. If you have trouble, send a bug report and include the contents of the file mpich/src/fortran/config.log.


    3. Q: When trying to compile Fortran code with a Fortran 90 or Fortran 95 compiler, I get error messages like

    Error: foo.f, line 30: Inconsistent datatype for argument 1 in MPI_SEND 
    

    A: The Fortran language requires that in two calls to the same subroutine, the types of arguments must be the same. That is, if you called MPI_SEND with a REAL buffer as the first argument and then called it with an INTEGER buffer as the first argument, a Fortran compiler can consider this an error. Few Fortran 77 compilers would complain about this; more Fortran 90 and Fortran 95 compilers check for this. There are two solutions. One is to use the MPI module (in the ``choice'' version: use the -choicemod option for mpif90); the other is to use an option to tell the Fortran 90 compiler to allow argument mismatches. For example, the argument -mismatch will cause the NAG Fortran compilers to allow mismatched arguments. Using the MPI module is the preferred approach.

    Fortran 77 users may sometimes see a similar message, particularly with later versions of g77. The option -Wno-globals will supress these warning messages.



Up: Problems compiling or linking Fortran programs Next: Problems Linking C Programs Previous: Problems compiling or linking Fortran programs