Find the answer to your Linux question:
Results 1 to 4 of 4
I am trying to compile fortran code using a make file and source code file copied from our /home/programs/ area to another location on our network (abra/bin), but haven't been ...
  1. #1
    Just Joined!
    Join Date
    Jul 2010
    Posts
    2

    Problem With Executing Fortran Makefile

    I am trying to compile fortran code using a make file and source code file copied from our /home/programs/ area to another location on our network (abra/bin), but haven't been able to do so due to problems with referencing subroutines.

    The original make file looks like this:

    program: program.f
    f77 program.f -o program \
    -L/home/programs/lib -lfmeta -lxyzutils

    When trying to execute the make file, the error message I get is:

    f77 program.f -o program \
    -L/home/programs/lib -lfmeta -lxyzutils
    /usr/bin/ld: cannot find -lfmeta
    collect2: ld returned 1 exit status
    make: *** [program} Error 1

    I've tried a few ways to get the make file to find the subroutines, but can't get anything to work. The subroutines by the way are in the form of compiled binary files (ie. libxyzutils.a and libfmeta.a).

    I appreciate the help.

  2. #2
    Linux Engineer rcgreen's Avatar
    Join Date
    May 2006
    Location
    the hills
    Posts
    1,114
    The subroutines by the way are in the form of compiled binary files (ie. libxyzutils.a and libfmeta.a).
    The linker may be looking for files with an .o extension
    (object files). By convention, .a files are assembly
    language.

  3. #3
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    The f77 command has been replaced by gfortran on most modern Linux systems that I have used.

    The commands gfortran and gcc have many options in common. The libraries are described as:
    Code:
           -llibrary
           -l library
               Search the library named library when linking.  (The second
               alternative with the library as a separate argument is only for
               POSIX compliance and is not recommended.)
    
               It makes a difference where in the command you write this option;
               the linker searches and processes libraries and object files in the
               order they are specified.  Thus, foo.o -lz bar.o searches library z
               after file foo.o but before bar.o.  If bar.o refers to functions in
               z, those functions may not be loaded.
    
               The linker searches a standard list of directories for the library,
               which is actually a file named liblibrary.a.  The linker then uses
               this file as if it had been specified precisely by name.
    
               The directories searched include several standard system
               directories plus any that you specify with -L.
    
               Normally the files found this way are library files---archive files
               whose members are object files.  The linker handles an archive file
               by scanning through it for members which define symbols that have
               so far been referenced but not defined.  But if the file that is
               found is an ordinary object file, it is linked in the usual
               fashion.  The only difference between using an -l option and
               specifying a file name is that -l surrounds library with lib and .a
               and searches several directories.
    
    -- excerpt from man gcc, q.v.
    as well as describing an assembler input file as:
    Code:
           file.s
               Assembler code.
    both of which agree with my experience.

    The error message suggests that the libraries are not in any of the standard places, nor in:
    Code:
    /home/programs/lib
    This can happen if you have placed the files in a directory other than /home/programs, and if the Makefile does not take that into account. Also the Makefile line does not list the libraries as dependencies, so that they may not have been made yet. The forms -Lpath, -lfile have different interpretations, so check that those are correct for your situation. For example, you might need to use something like:
    Code:
    f77 ... lib/fmeta.a ...
    and in the appropriate order as described in the man gcc excerpt above.

    Note that it would be unusual to have a login name of the form programs, as suggested by the path /home/programs.

    Because you said that the libraries are in the form of .a files, then the problem is probably the directory path issue. Try to fix that first. If you still have trouble, please tell us your distribution -- for example, the one I often use is:
    Code:
    OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
    Distribution        : Debian GNU/Linux 5.0
    and the compiler is often:
    Code:
    gfortran GNU Fortran (Debian 4.3.2-1.1) 4.3.2
    The directory tree structure may be useful to know:
    Code:
    tree /home/programs
    if that is where your code resides.

    If you post more code, Makefiles, error messages, etc., please use CODE tags -- select the lines with mouse, then click the # just above the editing box. That will make it easier to read and diagnose problems.

    Best wishes ... cheers, drl
    Last edited by drl; 07-31-2010 at 10:22 AM.
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  4. #4
    Just Joined!
    Join Date
    Jul 2010
    Posts
    2
    An update on this thread. I didn't pursue the problem much after posting the original thread, and recently resurrected the issue out of necessity. I appreciate the respnonses which were great at helping me understand the mechanics of compiling using assembler code and library structures.

    We had another guy look into the issue and he determined that the problem was due to a server upgrade to 64 bit hardware. The libararies were previously compiled using 32 bit and the updated compiler was looking for 64 bit libraries. Once we figured out how to recompile 64 bit versions of the libraries, the makefiles worked great.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...