[comp.sys.sgi] ar - the archiver

JORDAN@gmr.COM (02/28/90)

Can someone give me any tips on using ar, or lead me to any books that
might be able to help me.

I am able to create a library, add objects, and update symbol tables
(e.g. ar cr lib.a a.o b.o, or ar ts lib.a), BUT I would like the compilerr
to recognize it via a flag; for example, the way it recognizes -Zg, or -lgl_s.

Thanks for any help...

tp mugabi-jordan
gm systems engr ctr

davea@quasar.wpd.sgi.com (David B. Anderson) (03/02/90)

In article <9002281129.aa20377@SMOKE.BRL.MIL> JORDAN@gmr.COM writes:
>Can someone give me any tips on using ar, or lead me to any books that
>might be able to help me.
>
>I am able to create a library, add objects, and update symbol tables
>(e.g. ar cr lib.a a.o b.o, or ar ts lib.a), BUT I would like the compilerr
>to recognize it via a flag; for example, the way it recognizes -Zg, or -lgl_s.

This is easily done. Say you name your archive  libmy.a and have a copy
temporarily in /myliblocation.

	su       # need to be root for the cp to /usr/lib
	cp /myliblocation/libmy.a /usr/lib
	exit     # no need to be root any more
	cc t.c -lmy      #this works, since ld searches /usr/lib

# alternatively:
	mkdir /usr/local/lib
	cp /myliblocation/libmy.a /usr/local/lib    
	cc t.c -L/usr/local/lib  -lmy
	# the -Lpath adds the path to the ld search list

You'll find all this information via ``man ld''

As always, RTFM :-)
Regards,
[ David B. Anderson  Silicon Graphics  (415)335-1548  davea@sgi.com ]

robert@texas.esd.sgi.com (Robert Skinner) (03/02/90)

In article <9002281129.aa20377@SMOKE.BRL.MIL>, JORDAN@gmr.COM writes:
> Can someone give me any tips on using ar, or lead me to any books that
> might be able to help me.
> 
> I am able to create a library, add objects, and update symbol tables
> (e.g. ar cr lib.a a.o b.o, or ar ts lib.a), BUT I would like the compilerr
> to recognize it via a flag; for example, the way it recognizes -Zg, or
-lgl_s.
> 
> Thanks for any help...
> 
> tp mugabi-jordan

Look at the -L option in the man page for 'ld'.  It allows you to set
the directories 'ld' will use to search for libraries you have named
with -L.  For example, you can name your library libmylib.a, put it in
/usr/people/me/lib, and then have a link line that looks like

	cc ..... -L/usr/people/me/lib ... -lmylib

(cc just calls ld to link.)  This isn't much help for just one private
library, but its great if you have several.

The -Zg option is obsolete on 4D systems and should not be used.  It is
equivalent to using '-lgl -lm' in the link command.  Besides, explicitly
saying -lgl makes it easier to change to -lgl_s and back.  


Robert Skinner
robert@sgi.com

		Whoa Homer, don't have a cow.
				- Bart Simpson

ciemo@bananapc.wpd.sgi.com (Dave Ciemiewicz) (03/02/90)

In article <9002281129.aa20377@SMOKE.BRL.MIL>, JORDAN@gmr.COM writes:
> Can someone give me any tips on using ar, or lead me to any books that
> might be able to help me.
> 
> I am able to create a library, add objects, and update symbol tables
> (e.g. ar cr lib.a a.o b.o, or ar ts lib.a), BUT I would like the compilerr
> to recognize it via a flag; for example, the way it recognizes -Zg, or
-lgl_s.
> 
> Thanks for any help...
> 
> tp mugabi-jordan
> gm systems engr ctr

When you specify a library using -l<libsuffix>, the linker, ld, looks for the
file as /lib/lib<libsuffix>.a or as /usr/lib/lib<libsuffix>.a.  For instance,
by specifying -lgl_s, you are actually getting /usr/lib/libgl_s.a.  You can
specify additional library search paths by using -L<libdirectory> where
<libdirectory> is the directory containing your library (even . if you want).

If you wanted to look up a libraries in /usr/local/lib, for instance, you
could add to your cc or ld command line:

	-L/usr/local/lib -lmylib1 -lmylib2

and the libraries could actually be /usr/local/lib/libmylib1.a and
/usr/local/lib/mylib2.a.

See cc(1) and ld(1) for more details.

						--- Ciemo

mccalpin@vax1.acs.udel.EDU (John D Mccalpin) (03/02/90)

In article <9002281129.aa20377@SMOKE.BRL.MIL> JORDAN@gmr.COM writes:
>I am able to create a library, add objects, and update symbol tables
>(e.g. ar cr lib.a a.o b.o, or ar ts lib.a), BUT I would like the compilerr
>to recognize it via a flag; for example, the way it recognizes -Zg, or -lgl_s.

In article <52318@sgi.sgi.com> davea@quasar.UUCP (David B. Anderson) replies:

[example #1 deleted since it works fine....]

># alternatively:
> cp /myliblocation/libmy.a /usr/local/lib    
> cc t.c -L/usr/local/lib -lmy	# the -Lpath adds the path to the ld search list

Some notes on this technique:
(1) All of the SGI machines that I have used automagically search
    /usr/local/lib, so the -L/usr/local/lib option is not needed here.
(2) The -L option does not work on the old 3000 series machines.
    (At least with the f77 command, since -L is preempted so that
     you can request a program listing.)
-- 
John D. McCalpin - mccalpin@vax1.acs.udel.edu
		   mccalpin@delocn.udel.edu
		   mccalpin@scri1.scri.fsu.edu

davea@quasar.wpd.sgi.com (David B. Anderson) (03/02/90)

In article <5798@udccvax1.acs.udel.EDU>, mccalpin@vax1.acs.udel.EDU (John D Mccalpin) writes:
> In article <9002281129.aa20377@SMOKE.BRL.MIL> JORDAN@gmr.COM writes:
[stuff deleted]
> Some notes on this technique:
> (1) All of the SGI machines that I have used automagically search
>     /usr/local/lib, so the -L/usr/local/lib option is not needed here.
Yes.    John is right.     4D ld searches:
	/lib/   
	/usr/lib/cmplrs/cc(vers#)
	/usr/lib/   
	/usr/local/lib
in that order (by default).   We never create the /usr/lib/cmplrs directory.

Regards,
[ David B. Anderson  Silicon Graphics  (415)335-1548  davea@sgi.com ]

cdshaw@cs.UAlberta.CA (Chris Shaw) (03/04/90)

In article <52318@sgi.sgi.com> davea@quasar.UUCP (David B. Anderson) writes:
>This is easily done. Say you name your archive  libmy.a and have a copy
>temporarily in /myliblocation.
>
>	su       # need to be root for the cp to /usr/lib
>	cp /myliblocation/libmy.a /usr/lib
>	exit     # no need to be root any more
>	cc t.c -lmy      #this works, since ld searches /usr/lib
>[ David B. Anderson  Silicon Graphics  (415)335-1548  davea@sgi.com ]

This works fine, although you might not want to become root every 3 weeks
just to update the library. Use symbolic links, as follows.


    su
    cd /usr/lib					# goto lib directory
    ln -s /myliblocation/libmy.a libmy.a  	# link to your library
    exit	# now you don't have to do this again if libmy.a changes
--
Chris Shaw     University of Alberta
cdshaw@cs.UAlberta.ca           Now with new, minty Internet flavour!
CatchPhrase: Bogus as HELL !