[comp.unix.questions] Creating libraries of object module

saroff@wotan.think.com (steven saroff) (02/25/90)

How does one create personal libraries or archives of object modules to
like to.  I want to have a library of various useful sub program, and
just link to them with a -l or something akin to it when I am compiling
some larger code.

	


S.Z. Saroff (saroff@think.com)          o o   
Thinking Machines Corporation           (_)_____o
245 First St                     ~~~~~~~~~(_____)~~~~~~~~~~~~~~~~~~~~
Cambridge, MA 02142                        oo oo  The Bear who Swims 

gwyn@smoke.BRL.MIL (Doug Gwyn) (02/25/90)

In article <34230@news.Think.COM> saroff@wotan.think.com.UUCP (steven saroff) writes:
>How does one create personal libraries or archives of object modules to
>like to.  I want to have a library of various useful sub program, and
>just link to them with a -l or something akin to it when I am compiling
>some larger code.

All that the "ld" or "cc" option "-lxxx" option does is to in effect
expand in-line to the pathname /usr/lib/libxxx.a.  You can always
specify the pathname of any library archive that you wish to be
searched at that point in the link-editing process.  Such archives
are created and maintained via the "ar" utility, which is described
in the UNIX Programmer's Reference Manual.

For example,
	cc -o foo foo.o foosubs.o mylib.a -lm

gorpong@telxon.uucp (Gordon C. Galligher) (03/03/90)

In article <12233@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn) writes:
>In article <34230@news.Think.COM> saroff@wotan.think.com.UUCP (steven saroff) writes:
>>How does one create personal libraries or archives of object modules to
>>like to.  I want to have a library of various useful sub program, and
>>just link to them with a -l or something akin to it when I am compiling
>>some larger code.
>
>All that the "ld" or "cc" option "-lxxx" option does is to in effect
>expand in-line to the pathname /usr/lib/libxxx.a.  You can always
>specify the pathname of any library archive that you wish to be
>searched at that point in the link-editing process.  Such archives
>are created and maintained via the "ar" utility, which is described

Doug is absolutely correct about the 'ar' utility.  Another thing which he
didn't mention about the -l flag is the ability to use the -L_path_ flag.
This flag, when given, causes the loader (ld(1)) to search that directory
for libraries of the form libxxxx.a also.  This gives you the ability to
have a directory of libraries ($HOME/lib for example) and then on your cc
or ld command lines just give:
	 cc -o file .o_files -L$HOME/lib -lm -lmylib1 -lmylib2
Just another way to do the exact same thing.  This gives you a shortcut if
you happen to have more than one "local" library you will be using.

		-- Gordon.

Gordon C. Galligher  <|> ..!uunet!telxon!gorpong <|> telxon!gorpong@uunet.uu.net
Telxon Corporation   <|> "I am attempting, ma'am, to make a mnemonic memory
Akron, Ohio, 44313   <|> circuit out of stone knives and bearskins"  - Spock
(216) 867-3700 (3512)<|>	_City on the Edge of Forever_

gwyn@smoke.BRL.MIL (Doug Gwyn) (03/04/90)

In article <480@telxon.UUCP> gorpong@telxon.UUCP (Gordon C. Galligher) writes:
>Another thing which he didn't mention about the -l flag is the ability
>to use the -L_path_ flag.

I didn't mention it because it's not always available.  If you know the
pathnames for your libraries, you can always supply the full pathnames
instead of using the -l facility (with or without the aid of -L).