How to link fortran archives to program in makefile using f77? - SGI

This is a discussion on How to link fortran archives to program in makefile using f77? - SGI ; I tried 3 ways of linking to archives but "none" would compile. What do I do, cry? In all cases, I create the archives in separate directories using "ar -rcs" ... I did encounter a knowledgable person in the hallway ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: How to link fortran archives to program in makefile using f77?

  1. How to link fortran archives to program in makefile using f77?

    I tried 3 ways of linking to archives but "none" would compile.
    What do I do, cry?

    In all cases, I create the archives in separate directories using "ar
    -rcs" ...

    I did encounter a knowledgable person in the hallway and he said
    (2) below was the best thing to try and use, but he said to make
    sure $(LIBS) appears last in the f77 command when I use $(LIBS). I
    tried it but that also did not work.

    All the files involved are fortran.

    So, these are my three unsuccessful tries:

    (1) I named the archives /.../.../libar1.a and /.../.../libar2.a.
    Note: I specified "..." in this post for make believe paths to
    libraries. You can make up anything and put it there.

    The below compile error came from referencing the archives in the
    makefile using,

    LIBS = -L/usr/clusardi/dir1/ -lar1 -L/usr/clusardi/dir2/ -lar2

    The error message that I get is,

    ld32 : FATAL 9 : I/O error (-lar1.a) : No such file or directory
    f77 ERROR: /usr/lib32/cmplrs/ld32 returned non-zero status 32
    *** Error code 2 (bu21)

    (2) I named the archives /.../.../ar1.a and /.../.../ar2.a
    and I used,

    LIBS = /.../.../ar1.a /.../.../ar2.a

    The error that I get says that I have basically undefined
    identifiers.
    (3) I named the archives /.../.../ar1.a and /.../.../ar2.a
    and I used,

    LIBS = -l/.../.../ar1.a /.../.../ar2.a

    The error that I get is almost identical to (1) above.

    Thanks,
    Christopher Lusardi


  2. Re: How to link fortran archives to program in makefile using f77?

    In article <1118451772.112143.38970@z14g2000cwz.googlegroups.c om>,
    wrote:
    :I tried 3 ways of linking to archives but "none" would compile.

    :In all cases, I create the archives in separate directories using "ar
    :-rcs" ...

    1) I named the archives /.../.../libar1.a and /.../.../libar2.a.

    :The below compile error came from referencing the archives in the
    :makefile using,

    :LIBS = -L/usr/clusardi/dir1/ -lar1 -L/usr/clusardi/dir2/ -lar2

    :The error message that I get is,

    :ld32 : FATAL 9 : I/O error (-lar1.a) : No such file or directory
    :f77 ERROR: /usr/lib32/cmplrs/ld32 returned non-zero status 32

    That looks to me as if the linker is literally looking for a file
    named '-lar1.a' . Which might be what you have instructed it to
    do in the makefile : the default rules for Make do not include -any-
    reference to a "LIBS" variable, so something in your make file
    is controlling how "LIBS" is used.


    2) I named the archives /.../.../ar1.a and /.../.../ar2.a
    :and I used,

    :LIBS = /.../.../ar1.a /.../.../ar2.a

    :The error that I get says that I have basically undefined
    :identifiers.

    Which identifiers, though? Ones you defined in the libraries
    you were linking in? If you are not using f77 as the command
    for your link step, then the linker will not automatically
    add in the fortran libraries.

  3. Re: How to link fortran archives to program in makefile using f77?

    Walter Roberson wrote:
    > In article <1118451772.112143.38970@z14g2000cwz.googlegroups.c om>,
    > wrote:
    > :The error that I get says that I have basically undefined
    > :identifiers.
    >
    > Which identifiers, though? Ones you defined in the libraries
    > you were linking in? If you are not using f77 as the command
    > for your link step, then the linker will not automatically
    > add in the fortran libraries.


    Well, the problem was that ar1.a contained references to ar2.a, and
    ar2.a contained references to ar1.a.

    Thus, my fix is to try this : not use one of libraries but to use
    the other one in the definition of LIBS.

    In addition, I would add the fortran files in the library not
    referenced in LIBS to the variable OBJECTS with their dot f suffix.

    -------------------------------------------------------------------------------------------
    #Consequently the makefile becomes
    all = a.out

    LIBS = /usr/clusardi/dir1/ar1.a

    OBJECTS = file1.o file2.o file3.o file4.o /usr/clusardi/dir2/file.f

    a.out: $(OBJECTS)
    f77 $(LIBS) $(OBJECTS)
    -------------------------------------------------------------------------------------------

    What do you think, neat huh?

    Christopher Lusardi


  4. Re: How to link fortran archives to program in makefile using f77?

    But, I can use both libraries if I use them more than once in the
    definition of LIBS.

    For example,

    LIBS = /.../.../ar1.a /.../.../ar2.a /.../.../ar1.a

    Thank you,
    Christopher


  5. Re: How to link fortran archives to program in makefile using f77?

    In article <1118668465.272466.310650@o13g2000cwo.googlegroups. com>,
    clusardi2k@aol.com wrote:

    : But, I can use both libraries if I use them more than once in the
    : definition of LIBS.
    :
    : For example,
    :
    : LIBS = /.../.../ar1.a /.../.../ar2.a /.../.../ar1.a

    SGI's linker isn't very smart regarding circular linkage. It also doesn't handle
    out-of-order linkage (which circular is, by definition), which trips up a lot of
    people.

    You're best to just avoid circular linkage all together.


    Cheers - Tony 'Nicoya' Mantler

    --
    Tony 'Nicoya' Mantler -- Master of Code-fu -- nicoya@ubb.ca
    -- http://nicoya.feline.pp.se/ -- http://www.ubb.ca/ --

+ Reply to Thread