1 |
James Le Cuirot wrote: |
2 |
> Damn, I realised just as I hit send that there's a caveat here and |
3 |
> that's sub-dependencies. If you're building a partially static binary |
4 |
> then I think you're okay. A fully static binary obviously needs all its |
5 |
> dependencies to be static and that includes any sub-dependencies. |
6 |
|
7 |
Note that there isn't really a way to express "partially static" to the |
8 |
toolchain when building a binary. |
9 |
|
10 |
If you link a binary -static then that is always "fully static". No .so |
11 |
will satisfy any -l options. |
12 |
|
13 |
The only way a "partially static" binary gets created is when linking |
14 |
*without* -static but some -l libraries only exist as static libraries, |
15 |
or if a library/object archive is specified with full .a filename, |
16 |
without using -l. |
17 |
|
18 |
And "partially static" also only means that some dependencies were |
19 |
included into the binary, but unlike "fully static" the binary is |
20 |
not runnable without ld.so and a fitting libc. |
21 |
|
22 |
|
23 |
> If an executable statically links libwebp.a with JPEG support but you |
24 |
> don't have libjpeg.a then you'll end up with undefined references. |
25 |
|
26 |
It's a bit more complicated.. |
27 |
|
28 |
Assume: ( note: without -static ) |
29 |
|
30 |
gcc -o binary source.c /usr/lib/libwebp.a |
31 |
|
32 |
If libwebp requires libjpeg, and libwebp was not built to include |
33 |
libjpeg.a then the above will not build. So we try: |
34 |
|
35 |
gcc -o binary source.c /usr/lib/libwebp.a /usr/lib/libjpeg.a |
36 |
|
37 |
If both .a exist this builds, but binary is still *not* linked statically, |
38 |
at a minimum, ld.so and libc are still required to run it. |
39 |
|
40 |
If we do: |
41 |
|
42 |
gcc -o binary source.c /usr/lib/libwebp.a -ljpeg |
43 |
|
44 |
Then the compiler will pick any libjpeg that is available, preferably |
45 |
.so but if that can't be found then it will also look for .a. binary is |
46 |
still *not* static. |
47 |
|
48 |
|
49 |
Finally consider: |
50 |
|
51 |
gcc -static -o binary source.c -lwebp -ljpeg |
52 |
gcc -static -o binary source.c /usr/lib/libwebp.a /usr/lib/libjpeg.a |
53 |
|
54 |
The above two are equivalent, but only thanks to -static. This fails |
55 |
if either library .a is not found. When this succeeds, we have a static |
56 |
binary, which runs anywhere regardless of ld.so and libc. |
57 |
|
58 |
|
59 |
pkg-config .pc files for libraries are a very convenient solution to |
60 |
the problem of sub-dependencies. In the above case, libwebp.pc would |
61 |
perhaps have -lwebp in Libs and libjpeg in Requires.private (or maybe |
62 |
-ljpeg in Libs.private). |
63 |
|
64 |
|
65 |
> That probably explains why the ceph dependencies are as they are |
66 |
|
67 |
I think USE=static-libs is nice to have, and ideally (IMHO) it would |
68 |
be a global USE flag, respected by every package that installs a |
69 |
library. The flag says nothing about consumers, it only promises |
70 |
availability of the .a files, which I think is nice. |
71 |
|
72 |
One technical reason for a consumer to DEPEND on libotherpackage[static-libs] |
73 |
would be if an upstream Makefile has /usr/lib/libother.a instead of -lother, |
74 |
arguably it would make more sense to apply a patch to the Makefile then. |
75 |
|
76 |
Another technical reason would be that libotherpackage doesn't adhere to |
77 |
common sense/best practice for library ABI/API compatibility, and make |
78 |
the static library *different* from the shared object. If libotherpackage |
79 |
maintainer heroines have made it possible to have one SLOT installed as |
80 |
static library and another, incompatible, SLOT installed as shared object |
81 |
and the consumer maintainer might know that only the static variant works. |
82 |
This one is very hard to do anything about about in Gentoo, but it is also |
83 |
a very construed case. The closest I've seen to this is giflib, which |
84 |
changed API and ABI without bumping SONAME. |
85 |
|
86 |
|
87 |
//Peter |