Re: Linking a shared library against a C function

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: John Gray <jgray(at)beansindustry(dot)co(dot)uk>
Cc: PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Linking a shared library against a C function
Date: 2001-08-06 00:21:08
Message-ID: Pine.LNX.4.30.0108060213510.11162-100000@peter.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

John Gray writes:

> Is it OK just to link the .so of my backend function against the expat
> library? i.e. to do
>
> gcc -shared -lexpat -o pgxml.so pgxml.o
>
> as the link stage (it seems to work fine) -or is there a portability
> problem with this?

On some platforms the dynamic loader will have to load the libexpat.so
object separately before the pgxml.so object, otherwise loading the latter
will fail with unresolved symbols. (This is either because the dynamic
loader ignores the libraries dependencies, or because the system doesn't
allow shared libraries to have dependencies at all.) In those cases the
only solution is to use something like libtool. However, those systems
are getting rarer, so you ought to be safe as a contrib item anyway.

> IF this is OK, would it be sensible to change the platform-specific
> makefile %.so rule to allow the specification of extra instance specific
> flags i.e. (example from Makefile.linux)
>
> %.so: %.o
> $(CC) -shared -o $@ $<
>
> changed to:
>
> %.so: %.o
> $(CC) -shared $(DLLINKFLAGS) -o $@ $<
>
> or something similar, which would prevent me from having to override
> the global rule and allow greater portability.

Use the Makefile.shlib interface. The rules in Makefile.port aren't very
powerful.

--
Peter Eisentraut peter_e(at)gmx(dot)net http://funkturm.homeip.net/~peter

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Larry Rosenman 2001-08-06 00:23:38 Re: Autoconf 2.50 is out (was Re: [PATCHES] Re: OpenUnix 8 Patch)
Previous Message Hiroshi Inoue 2001-08-05 23:33:13 Re: Re: OID wraparound: summary and proposal