Re; Fortran Library problem

Re; Fortran Library problem

Post by Andrew A. Pai » Tue, 15 Oct 1996 04:00:00

My thanks to all who replied to my FORTRAN problem.
(Kevin was my first respondee and was correct)

The order of the arguments was wrong!

This now works properly:

       f77 -o test.f -L. -lgq610



Note:  I have included the various responses, as I
gathered some useful info that might interest others.

: I need to create a fortran library from a collection of subroutines.  They are
: interdependent and so the library needs to be "searched" as often as needed
: in order to resolve all references.
: This is a summary of what I believe is the correct way to proceed (I've
: had some local help but it's not being solved).
: 1) compiled all routines:   f77 *.f -O -c
: 2) started the library :   ar rcv libgq610.a  sub1.o    (the 1st subroutine)
: 3) added remaining routines one at a time:
:          ar  qv  libgq610.a  sub2.o
:             ( etc. until all are loaded)
: 4) now compile/link/load:
:      f77  -L. -lgq610 -o  test.f



Your order is wrong.  Libraries must go at the end.  Try:

f77 -o test.f -L. -lgq610

        Kevin W. Thomas
        Sun System Administrator & Meteorologist
        National Severe Storms Laboratory
        Norman, Oklahoma

you may need to move the -llibname to the end of the compile line.
that's probably not it, tho.

our library doesn't self-reference in a major way.  however, the
recommended way to do ar style libs involves tsort before inserting.
check tsort man page.

it may be necessary to -llibname -llibname , ie, link to it more
than once.  libs aren't searched and re-searched.  Just one pass.
how much tsort will lessen that pain, I don't know.

no other ideas.
Jay Scott               512-835-3553

Applied Research Labs, Computer Science Div.
University of Texas at Austin

Quote:> 4) now compile/link/load:

>      f77  -L. -lgq610 -o  test.f

        f77 -o test.f -L. -lgq610

Archives libraries are searched once for references when they are
encountered.  It isn't until after the library is processed that
the references from test.f are detected.



Quote:> When you do an "f77" (no arguments) it tells you that

> the order is:  f77 [options] files

> Sooo,  I took this to mean that, anything that has an "-"
> prefacing it (f77 -flags) meant that it was an option.

Oh, I see.  The usage message could be more intuitive.  I filed
a bug to try and get it improved.



BTW ...

Quote:> 3) added remaining routines one at a time:

>         ar  qv  libgq610.a  sub2.o
>            ( etc. until all are loaded)

You can add *all* the objects to the archive in one go ...

        ar rcv libgq610.o sub1.o sub2.o ....

Or you could generate a shared object (in which case your previous
link-line would have worked :-).  Confused? ;-)  Check out the
``Linker and Libraries Guide'', which is part of the Software
Developers Guide in the Answerbook.


That's the procedure I've used with success to create the library.  You may
need to
reorder the arguments in the later compilation:

     f77 -o test.f -L. -lgq610

Mike Johnson

The linker ld starts with the main program and searches for symbols therein
left-to-right. You should mention "-o"
before -L and -l. One also usually puts options before filenames, although
in the first "f77"-lines it does not matter.

  f77 -O -c sub1.f
  f77 ...
  ar rcv libgq610.a  sub1.o
  ar ...
  f77 -o test.f -L. -lgq610

You wisely named your executable "" and not "test". Naming
a program "test" might interfere with /bin/test and cause all sorts
of weirdness.

If you have multiple libraries, they also must be in the correct order,
left-to-right. If a routine in your libgq610.a uses a function from
/usr/lib/libm.a, you must say

     ... -lgq610 -lm

and not
     ... -lm -lgq610

Using Makefiles is also suggested.

 - Andi Karrer



    _!_______+---     ___  _________  _________            ____/\.
   _|________|__| |_____|  |_A_&_P_|  |_A_&_P_|  >E-MAIL<  |_____|
  /o=OOOO -OOOOo ~ oo oo ~~ ooo ooo ~~ ooo ooo ~~ oo  oo ~~ oo oo

Andrew A. Paine, CS               (614) 292-6518 Office
410 Arps Hall                     (614) 292-3906 FAX
The Ohio State University         (614) 438-8413 (digital pager)
1945 North High Street                  
Columbus, Ohio 43210-1172        

     Yesterday is history,  
       Tomorrow's a mystery,
         Today is a Gift and that's we call it the Present !



1. HELP!!! Fortran library or Linux library error!


I trying to compile a program in fortran language.
During the compilation I have the following errors:

../inclan/src/inclan.a(unix.o): In function `ifork_':
unix.o(.text+0xc): undefined reference to `fork_'
../inclan/src/inclan.a(unix.o): In function `mfork_':
unix.o(.text+0x18): undefined reference to `fork_'
../inclan/src/inclan.a(unix.o): In function `iwait_':
unix.o(.text+0x43): undefined reference to `wait_'
../inclan/src/inclan.a(unix.o): In function `isystm_':
unix.o(.text+0x72): undefined reference to `system_'
../inclan/src/inclan.a(unix.o): In function `igtpid_':
unix.o(.text+0x7c): undefined reference to `getpid_'
../inclan/src/inclan.a(unix.o): In function `iwall_':
unix.o(.text+0xd4): undefined reference to `time_'
unix.o(.text+0xde): undefined reference to `time_'
../inclan/src/inclan.a(unix.o): In function `uxtime_':
unix.o(.text+0x100): undefined reference to `time_'
../inclan/src/inclan.a(unix.o): In function `uxdate_':
unix.o(.text+0x178): undefined reference to `time_'
../inclan/src/inclan.a(unix.o): In function `usignl_':
unix.o(.text+0x1ff): undefined reference to `signal_'
../inclan/src/inclan.a(unix.o): In function `istamp_':
unix.o(.text+0x227): undefined reference to `stat_'
make[1]: *** [pseudyanaexe.linux] Error 1

What are these errors?

I haven't aome libraries?

I have linux 2.0.35, g77 0.5.22, gcc

Thank in advance
---------------------------     /\\\\\\
Enrico Morelli                 /\|||||||
                              /__ __ ::;
Lab. NMR - Dpt. Chemistry    |  O O    _
University of Florence          /     | |
Phone: +39 55 2757539          |_/     _|
Fax  : +39 55 2757555           |_/   |
                                |    /

-----------------------------  \_ /

2. sendmail, automount, and tape backups...

3. Compilation problem with X libraries (PGPLOT with Intel Fortran Compiler)

4. PPP

5. Problem in "Open" Fortran Library while using Exceed "dtterm"

6. Remote Printing Queue not enabled

7. Compiling C programs w/ FORTRAN nag libraries

8. cern http 3.0 problems

9. Fortran NAG libraries

10. Fortran IMSL Libraries?

11. Fortran Runtime Libraries

12. convert fortran subroutines in library

13. looking for fortran run-time libraries for solaris