Writing Shared Libraries, first draft
Scott James Remnant
scott at netsplit.com
Fri Nov 5 13:38:54 EET 2004
On Thu, 2004-11-04 at 20:34 +0000, Mike Hearn wrote:
> I thought I'd try writing an equivalent for library developers. This
> document gathers together generally accepted best practices and sticks
> them all in one document complete with examples. Here it is:
>
You forgot any mention of the most important point ... shared libraries
contain PIC code, static libraries contain non-PIC code.
Libraries should only be parallel-installable across major version
boundaries, and only then if the newer version doesn't entirely
deprecate the former from a development POV.
GTK+ is a good example of a library where the new major version doesn't
entirely deprecate the former, you still want to develop applications
that use GTK+ 1.x.
This is actually a rarer case than it seems, often you want to
deliberately force people into always using the latest development
version of your library ... in which case it makes more sense to make
them hard to parallel install.
Header versioning isn't required ... if you correctly maintain backwards
compatibility within a major version you don't need it. Applications
simply use whatever versions of library they require and check the
headers declare them (or pkg-config knows the version is recent enough)
in configure.ac
Also it tends to promote ABI breakage.
struct foo {
:
#if XXX_MINOR_VERSION > 3
unsigned long long member;
#else
unsigned short member;
#endif
:
};
Structure size changes are actually far less of a problem than you make
out. Structures are almost never passed-by-value into a function, and
rarely used-by-value in another structure.
The exception, of course, is GTK+ which relies on being able to
predictably embed structures inside each other.
In particular your use of function pointers is dangerous, as there's no
way of predictably and portably counting how many function pointers you
need to remove, and how many alternate padding fields you need to
replace. Sure you can best guess and hope it works, but you'll get
bitten one day.
Scott
--
Have you ever, ever felt like this?
Had strange things happen? Are you going round the twist?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.freedesktop.org/archives/xdg/attachments/20041105/fc3c024e/attachment.pgp
More information about the xdg
mailing list