[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Not everyone is linking shared libraries to libc



On Fri, Feb 23, 2001 at 06:20:47PM +0100, Simon Richter wrote:
> On Fri, 23 Feb 2001, Wichert Akkerman wrote:
> 
> > > Can people please run the attached script on their system and see if it
> > > finds more broken packages on their system?
> 
> > The attached script had a slight typo, new version attached.
> 
> Say, do all libraries need to link against libc, or just those that use
> libc functions?

Any library that is loaded by ld.so has to be linked via gcc. IOW,
the library cannot be linked like:

	gcc -fPIC -c foo.c -o foo.o
	gcc -fPIC -c blah.c -o foo.o
	ld -soname libfoo.so.1 -shared -Bdynamic foo.o blah.o -o libfoo.so.1

Since this will not link to libc, nor does it include any of the crt?.o
files (constructor/destructor for the library, helps ld.so). It must be
linked like:

	gcc -Wl,-soname,libfoo.so.1 -shared foo.o blah.o -o libfoo.so.1

If you do this with the -v option to gcc, you will see the link line.
Not that this link line changes based on some compile options such as
-g, -profile, -pg, etc.. This also links to libgcc.a, which may be
needed. The libgcc.a used can also depend on compile options (like -m32
and -m64 on sparc/sparc64 compiles). It will also make sure that -lc is
compiled in. The -lc used can also depend on compile options (-profile
links with -lc_p for instance).

If it is not built properly, libraries tend to be buggy, and crap out in
odd ways. It also makes it harder to compile with special options like
profiling, since the links command line needs to change as opposed to
just exporting a different CFLAGS and LDFLAGS.

Ben

-- 
 -----------=======-=-======-=========-----------=====------------=-=------
/  Ben Collins  --  ...on that fantastic voyage...  --  Debian GNU/Linux   \
`  bcollins@debian.org  --  bcollins@openldap.org  --  bcollins@linux.com  '
 `---=========------=======-------------=-=-----=-===-======-------=--=---'



Reply to: