-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
351 lines (344 loc) · 18 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
g++ --std=c++11 -fPIC -fvisibility=hidden -c fooapi/foo.cpp -o fooapi/foo.o
g++ -fPIC -fvisibility=hidden -shared -Wl,-soname,libfoo.so.1.0.0 -o lib/libfoo.so.1.0.0 fooapi/foo.o
ldd lib/libfoo.so.1.0.0
linux-vdso.so.1 => (0x00007ffe0e12c000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fcf7f9dc000)
libm.so.6 => /lib64/libm.so.6 (0x00007fcf7f6da000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fcf7f4c4000)
libc.so.6 => /lib64/libc.so.6 (0x00007fcf7f0f7000)
/lib64/ld-linux-x86-64.so.2 (0x00007fcf7fee7000)
g++ --std=c++11 -fPIC -fvisibility=hidden -c fooapir2/foo.cpp -o fooapir2/foo.o
g++ -fPIC -fvisibility=hidden -shared -Wl,-soname,libfoo.so.1.0.2 -o lib/libfoo.so.1.0.2 fooapir2/foo.o
ldd lib/libfoo.so.1.0.*
lib/libfoo.so.1.0.0:
linux-vdso.so.1 => (0x00007fffc7d5d000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f467a3fc000)
libm.so.6 => /lib64/libm.so.6 (0x00007f467a0fa000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f4679ee4000)
libc.so.6 => /lib64/libc.so.6 (0x00007f4679b17000)
/lib64/ld-linux-x86-64.so.2 (0x00007f467a907000)
lib/libfoo.so.1.0.2:
linux-vdso.so.1 => (0x00007ffcc05fd000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f7968bfe000)
libm.so.6 => /lib64/libm.so.6 (0x00007f79688fc000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f79686e6000)
libc.so.6 => /lib64/libc.so.6 (0x00007f7968319000)
/lib64/ld-linux-x86-64.so.2 (0x00007f7969109000)
cd lib; ln -s libfoo.so.1.0.0 libfoo.so.1; ln -s libfoo.so.1 libfoo.so; cd ..
total 40
lrwxrwxrwx. 1 amd amd 11 Sep 4 11:30 libfoo.so -> libfoo.so.1
lrwxrwxrwx. 1 amd amd 15 Sep 4 11:30 libfoo.so.1 -> libfoo.so.1.0.0
-rwxrwxr-x. 1 amd amd 20120 Sep 4 11:16 libfoo.so.1.0.0
-rwxrwxr-x. 1 amd amd 20120 Sep 4 11:23 libfoo.so.1.0.2
g++ --std=c++11 -Ifooapi -fPIC -fvisibility=hidden -c barapi/bar.cpp -o barapi/bar.o
g++ -fPIC -fvisibility=hidden -shared -Wl,-soname,libbar.so.1.0.0 -o lib/libbar.so.1.0.0 barapi/bar.o
cd lib; ln -s libbar.so.1.0.0 libbar.so.1; ln -s libbar.so.1 libbar.so; cd ..
total 60
lrwxrwxrwx. 1 amd amd 11 Sep 4 11:37 libbar.so -> libbar.so.1
lrwxrwxrwx. 1 amd amd 15 Sep 4 11:37 libbar.so.1 -> libbar.so.1.0.0
-rwxrwxr-x. 1 amd amd 20160 Sep 4 11:34 libbar.so.1.0.0
lrwxrwxrwx. 1 amd amd 11 Sep 4 11:30 libfoo.so -> libfoo.so.1
lrwxrwxrwx. 1 amd amd 15 Sep 4 11:30 libfoo.so.1 -> libfoo.so.1.0.0
-rwxrwxr-x. 1 amd amd 20120 Sep 4 11:16 libfoo.so.1.0.0
-rwxrwxr-x. 1 amd amd 20120 Sep 4 11:23 libfoo.so.1.0.2
g++ --std=c++11 -Ifooapi -Ibarapi main.cpp -o main -Llib -lfoo -lbar
LD_LIBRARY_PATH=lib ldd ./main
linux-vdso.so.1 => (0x00007ffca29e4000)
libfoo.so.1.0.0 => lib/libfoo.so.1.0.0 (0x00007f5a8572a000)
libbar.so.1.0.0 => lib/libbar.so.1.0.0 (0x00007f5a85526000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f5a8521f000)
libm.so.6 => /lib64/libm.so.6 (0x00007f5a84f1d000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f5a84d07000)
libc.so.6 => /lib64/libc.so.6 (0x00007f5a8493a000)
/lib64/ld-linux-x86-64.so.2 (0x00007f5a8592e000)
Make libbar depend on libfoo - recompile libbar and main app
g++ -fPIC -fvisibility=hidden -shared -Wl,-soname,libbar.so.1.0.0 -o lib/libbar.so.1.0.0 barapi/bar.o -Llib -lfoo
ldd lib/libbar.so
linux-vdso.so.1 => (0x00007ffc5db8e000)
libfoo.so.1.0.0 => not found
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f82064d2000)
libm.so.6 => /lib64/libm.so.6 (0x00007f82061d0000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f8205fba000)
libc.so.6 => /lib64/libc.so.6 (0x00007f8205bed000)
/lib64/ld-linux-x86-64.so.2 (0x00007f82069dd000)
LD_LIBRARY_PATH=lib ldd lib/libbar.so
linux-vdso.so.1 => (0x00007fff7f1f5000)
libfoo.so.1.0.0 => lib/libfoo.so.1.0.0 (0x00007f3566b82000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f356687b000)
libm.so.6 => /lib64/libm.so.6 (0x00007f3566579000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f3566363000)
libc.so.6 => /lib64/libc.so.6 (0x00007f3565f96000)
/lib64/ld-linux-x86-64.so.2 (0x00007f3566f8a000)
g++ --std=c++11 -Ifooapi -Ibarapi main.cpp -o main -Llib -lbar
/usr/bin/ld: warning: libfoo.so.1.0.0, needed by lib/libbar.so, not found (try using -rpath or -rpath-link)
/tmp/ccPtxeEW.o: In function `main':
main.cpp:(.text+0xa): undefined reference to `foo'
collect2: error: ld returned 1 exit status
Use rpath to the rescue - recompile libbar telling loader to look in for dep libs
g++ -fPIC -fvisibility=hidden -shared -Wl,-soname,libbar.so.1.0.0 -Wl,-rpath,$ORIGIN -o lib/libbar.so.1.0.0 barapi/bar.o -Llib -lfoo
Dynamic section at offset 0x2d98 contains 30 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libfoo.so.1.0.0]
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000000e (SONAME) Library soname: [libbar.so.1.0.0]
0x000000000000000f (RPATH) Library rpath: [$ORIGIN]
0x000000000000000c (INIT) 0x1560
0x000000000000000d (FINI) 0x2010
0x0000000000000019 (INIT_ARRAY) 0x202d68
0x000000000000001b (INIT_ARRAYSZ) 16 (bytes)
0x000000000000001a (FINI_ARRAY) 0x202d78
0x000000000000001c (FINI_ARRAYSZ) 8 (bytes)
0x000000006ffffef5 (GNU_HASH) 0x1f0
0x0000000000000005 (STRTAB) 0x830
0x0000000000000006 (SYMTAB) 0x2a8
0x000000000000000a (STRSZ) 1790 (bytes)
0x000000000000000b (SYMENT) 24 (bytes)
0x0000000000000003 (PLTGOT) 0x203000
0x0000000000000002 (PLTRELSZ) 960 (bytes)
0x0000000000000014 (PLTREL) RELA
0x0000000000000017 (JMPREL) 0x11a0
0x0000000000000007 (RELA) 0x1038
0x0000000000000008 (RELASZ) 360 (bytes)
0x0000000000000009 (RELAENT) 24 (bytes)
0x000000006ffffffe (VERNEED) 0xfa8
0x000000006fffffff (VERNEEDNUM) 3
0x000000006ffffff0 (VERSYM) 0xf2e
0x000000006ffffff9 (RELACOUNT) 4
0x0000000000000000 (NULL) 0x0
readelf -d main
Dynamic section at offset 0xdd8 contains 29 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libbar.so.1.0.0]
0x0000000000000001 (NEEDED) Shared library: [libfoo.so.1.0.0]
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000000c (INIT) 0x400500
0x000000000000000d (FINI) 0x4006f4
0x0000000000000019 (INIT_ARRAY) 0x600dc0
0x000000000000001b (INIT_ARRAYSZ) 8 (bytes)
0x000000000000001a (FINI_ARRAY) 0x600dc8
0x000000000000001c (FINI_ARRAYSZ) 8 (bytes)
0x000000006ffffef5 (GNU_HASH) 0x400298
0x0000000000000005 (STRTAB) 0x4003c0
0x0000000000000006 (SYMTAB) 0x4002d0
0x000000000000000a (STRSZ) 171 (bytes)
0x000000000000000b (SYMENT) 24 (bytes)
0x0000000000000015 (DEBUG) 0x0
0x0000000000000003 (PLTGOT) 0x601000
0x0000000000000002 (PLTRELSZ) 72 (bytes)
0x0000000000000014 (PLTREL) RELA
0x0000000000000017 (JMPREL) 0x4004b8
0x0000000000000007 (RELA) 0x4004a0
0x0000000000000008 (RELASZ) 24 (bytes)
0x0000000000000009 (RELAENT) 24 (bytes)
0x000000006ffffffe (VERNEED) 0x400480
0x000000006fffffff (VERNEEDNUM) 1
0x000000006ffffff0 (VERSYM) 0x40046c
0x0000000000000000 (NULL) 0x0
g++ --std=c++11 -Ifooapi -Ibarapi main.cpp -o main -Llib -lbar -lfoo
ldd main
linux-vdso.so.1 => (0x00007ffc4efc7000)
libbar.so.1.0.0 => not found
libfoo.so.1.0.0 => not found
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fb8a221f000)
libm.so.6 => /lib64/libm.so.6 (0x00007fb8a1f1d000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fb8a1d07000)
libc.so.6 => /lib64/libc.so.6 (0x00007fb8a193a000)
/lib64/ld-linux-x86-64.so.2 (0x00007fb8a2526000)
LD_LIBRARY_PATH=lib ./main
foo doimpl 10 version 1 foo
foo doimpl 20 version 1 foo
bar doimpl 20 version 1 bar
Upgrade libfoo
cd lib; rm libfoo.so.1; rm libfoo.so; ln -s libfoo.so.1.0.2 libfoo.so.1; ln -s libfoo.so.1 libfoo.so; cd ..
total 60
lrwxrwxrwx. 1 amd amd 11 Sep 4 11:37 libbar.so -> libbar.so.1
lrwxrwxrwx. 1 amd amd 15 Sep 4 11:37 libbar.so.1 -> libbar.so.1.0.0
-rwxrwxr-x. 1 amd amd 20160 Sep 4 11:47 libbar.so.1.0.0
lrwxrwxrwx. 1 amd amd 11 Sep 4 13:06 libfoo.so -> libfoo.so.1
lrwxrwxrwx. 1 amd amd 15 Sep 4 13:06 libfoo.so.1 -> libfoo.so.1.0.2
-rwxrwxr-x. 1 amd amd 20120 Sep 4 11:16 libfoo.so.1.0.0
-rwxrwxr-x. 1 amd amd 20120 Sep 4 11:23 libfoo.so.1.0.2
LD_LIBRARY_PATH=lib ./main
foo doimpl 10 version 1 foo
foo doimpl 20 version 1 foo
bar doimpl 20 version 1 bar
main app works as libfoo.so.1.0.0 - old version still exists
mv lib/libfoo.so.1.0.0 lib/hide_libfoo.so.1.0.0
total 60
-rwxrwxr-x. 1 amd amd 20120 Sep 4 11:16 hide_libfoo.so.1.0.0
lrwxrwxrwx. 1 amd amd 11 Sep 4 11:37 libbar.so -> libbar.so.1
lrwxrwxrwx. 1 amd amd 15 Sep 4 11:37 libbar.so.1 -> libbar.so.1.0.0
-rwxrwxr-x. 1 amd amd 20160 Sep 4 11:47 libbar.so.1.0.0
lrwxrwxrwx. 1 amd amd 11 Sep 4 13:06 libfoo.so -> libfoo.so.1
lrwxrwxrwx. 1 amd amd 15 Sep 4 13:06 libfoo.so.1 -> libfoo.so.1.0.2
-rwxrwxr-x. 1 amd amd 20120 Sep 4 11:23 libfoo.so.1.0.2
LD_LIBRARY_PATH=lib ./main
./main: error while loading shared libraries: libfoo.so.1.0.0: cannot open shared object file: No such file or directory
Recompile libbar to use upgraded libfoo
readelf -d lib/libbar.so | head -15
Dynamic section at offset 0x2d98 contains 30 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libfoo.so.1.0.0]
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000000e (SONAME) Library soname: [libbar.so.1.0.0]
0x000000000000000f (RPATH) Library rpath: [$ORIGIN]
0x000000000000000c (INIT) 0x1560
0x000000000000000d (FINI) 0x2010
0x0000000000000019 (INIT_ARRAY) 0x202d68
0x000000000000001b (INIT_ARRAYSZ) 16 (bytes)
0x000000000000001a (FINI_ARRAY) 0x202d78
g++ -fPIC -fvisibility=hidden -shared -Wl,-soname,libbar.so.1.0.1 -Wl,-rpath,$ORIGIN -o lib/libbar.so.1.0.1 barapi/bar.o -Llib -lfoo
total 80
-rwxrwxr-x. 1 amd amd 20120 Sep 4 11:16 hide_libfoo.so.1.0.0
lrwxrwxrwx. 1 amd amd 11 Sep 4 11:37 libbar.so -> libbar.so.1
lrwxrwxrwx. 1 amd amd 15 Sep 4 11:37 libbar.so.1 -> libbar.so.1.0.0
-rwxrwxr-x. 1 amd amd 20160 Sep 4 11:47 libbar.so.1.0.0
-rwxrwxr-x. 1 amd amd 20160 Sep 4 13:15 libbar.so.1.0.1
lrwxrwxrwx. 1 amd amd 11 Sep 4 13:06 libfoo.so -> libfoo.so.1
lrwxrwxrwx. 1 amd amd 15 Sep 4 13:06 libfoo.so.1 -> libfoo.so.1.0.2
-rwxrwxr-x. 1 amd amd 20120 Sep 4 11:23 libfoo.so.1.0.2
libbar.so.1.0.1 is new
./main: error while loading shared libraries: libfoo.so.1.0.0: cannot open shared object file: No such file or directory
readelf -d main | head -10
Dynamic section at offset 0xdd8 contains 29 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libbar.so.1.0.0]
0x0000000000000001 (NEEDED) Shared library: [libfoo.so.1.0.0]
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000000c (INIT) 0x400500
main app still linked with old libbar, fails
readelf -d lib/libbar.so.1.0.1 | head -10
Dynamic section at offset 0x2d98 contains 30 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libfoo.so.1.0.2]
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000000e (SONAME) Library soname: [libbar.so.1.0.1]
0x000000000000000f (RPATH) Library rpath: [$ORIGIN]
new libbar.so.1.0.1 needs libfoo.so.1.0.2
rebuild main app
g++ --std=c++11 -Ifooapi -Ibarapi main.cpp -o main -Llib -lbar -lfoo
/usr/bin/ld: warning: libfoo.so.1.0.0, needed by lib/libbar.so, not found (try using -rpath or -rpath-link)
Update libbar so links
cd lib; rm libbar.so.1; rm libbar.so; ln -s libbar.so.1.0.1 libbar.so.1; ln -s libbar.so.1 libbar.so; cd ..
total 80
-rwxrwxr-x. 1 amd amd 20120 Sep 4 11:16 hide_libfoo.so.1.0.0
lrwxrwxrwx. 1 amd amd 11 Sep 4 13:20 libbar.so -> libbar.so.1
lrwxrwxrwx. 1 amd amd 15 Sep 4 13:20 libbar.so.1 -> libbar.so.1.0.1
-rwxrwxr-x. 1 amd amd 20160 Sep 4 11:47 libbar.so.1.0.0
-rwxrwxr-x. 1 amd amd 20160 Sep 4 13:15 libbar.so.1.0.1
lrwxrwxrwx. 1 amd amd 11 Sep 4 13:06 libfoo.so -> libfoo.so.1
lrwxrwxrwx. 1 amd amd 15 Sep 4 13:06 libfoo.so.1 -> libfoo.so.1.0.2
-rwxrwxr-x. 1 amd amd 20120 Sep 4 11:23 libfoo.so.1.0.2
libbar.so points to the latest, libfoo.so points to what libbar needs
rebuild main app
g++ --std=c++11 -Ifooapi -Ibarapi main.cpp -o main -Llib -lbar -lfoo
It worked
ldd main
linux-vdso.so.1 => (0x00007ffc04bfb000)
libbar.so.1.0.1 => not found
libfoo.so.1.0.2 => not found
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f7803266000)
libm.so.6 => /lib64/libm.so.6 (0x00007f7802f64000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f7802d4e000)
libc.so.6 => /lib64/libc.so.6 (0x00007f7802981000)
/lib64/ld-linux-x86-64.so.2 (0x00007f780356d000)
LD_LIBRARY_PATH=lib ldd main
linux-vdso.so.1 => (0x00007ffe838c8000)
libbar.so.1.0.1 => lib/libbar.so.1.0.1 (0x00007f9141780000)
libfoo.so.1.0.2 => lib/libfoo.so.1.0.2 (0x00007f914157c000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f9141275000)
libm.so.6 => /lib64/libm.so.6 (0x00007f9140f73000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f9140d5d000)
libc.so.6 => /lib64/libc.so.6 (0x00007f9140990000)
/lib64/ld-linux-x86-64.so.2 (0x00007f9141984000)
Shows main using correct versions of libs
LD_LIBRARY_PATH=lib ./main
foo 2 doimpl 10 version 2 foo
foo 2 doimpl 20 version 2 foo
bar doimpl 20 version 1 bar
Note libfoo version 2 got called by bar
How to make updates to foo so libbar doesn't need to be recompiled
use correct soname spec
build libfoo
change just libfile names
g++ -fPIC -fvisibility=hidden -shared -Wl,-soname,libfoo.so.1 -o lib.so/libfoo.so.1.0.0 fooapi/foo.o
cd lib.so; ln -s libfoo.so.1.0.0 libfoo.so.1; ln -s libfoo.so.1 libfoo.so; cd ..
g++ -fPIC -fvisibility=hidden -shared -Wl,-soname,libbar.so.1 -Wl,-rpath,$ORIGIN -o lib.so/libbar.so.1.0.0 barapi/bar.o -Llib.so -lfoo
ldd lib.so/libbar.so.1.0.0
linux-vdso.so.1 => (0x00007ffc2a17c000)
libfoo.so.1 => /datadisk/git-repos/sharedlib/lib.so/libfoo.so.1 (0x00007f46b803e000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f46b7d37000)
libm.so.6 => /lib64/libm.so.6 (0x00007f46b7a35000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f46b781f000)
libc.so.6 => /lib64/libc.so.6 (0x00007f46b7452000)
/lib64/ld-linux-x86-64.so.2 (0x00007f46b8446000)
Note libbar only depends on libfoo.so.1 not libfoo.so.1.0.0, last 2 digits dont care
Build main
/usr/bin/ld: cannot find -lbar
collect2: error: ld returned 1 exit status
cd lib.so; ln -s libbar.so.1.0.0 libbar.so.1; ln -s libbar.so.1 libbar.so; cd ..
g++ --std=c++11 -Ifooapi -Ibarapi main.cpp -o main -Llib.so -lbar -lfoo
ldd main
linux-vdso.so.1 => (0x00007ffec730a000)
libbar.so.1 => not found
libfoo.so.1 => not found
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f2547558000)
libm.so.6 => /lib64/libm.so.6 (0x00007f2547256000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f2547040000)
libc.so.6 => /lib64/libc.so.6 (0x00007f2546c73000)
/lib64/ld-linux-x86-64.so.2 (0x00007f254785f000)
note the lib versions conform to soname spec
LD_LIBRARY_PATH=lib.so ./main
foo doimpl 10 version 1 foo
foo doimpl 20 version 1 foo
bar doimpl 20 version 1 bar
Now update libfoo
g++ -fPIC -fvisibility=hidden -shared -Wl,-soname,libfoo.so.1 -o lib.so/libfoo.so.1.0.2 fooapir2/foo.o
keep soname_spec compatible but filename changed
ls -l lib.so
total 60
lrwxrwxrwx. 1 amd amd 11 Sep 4 13:34 libbar.so -> libbar.so.1
lrwxrwxrwx. 1 amd amd 15 Sep 4 13:34 libbar.so.1 -> libbar.so.1.0.0
-rwxrwxr-x. 1 amd amd 20160 Sep 4 13:31 libbar.so.1.0.0
lrwxrwxrwx. 1 amd amd 11 Sep 4 13:30 libfoo.so -> libfoo.so.1
lrwxrwxrwx. 1 amd amd 15 Sep 4 13:30 libfoo.so.1 -> libfoo.so.1.0.0
-rwxrwxr-x. 1 amd amd 20120 Sep 4 13:29 libfoo.so.1.0.0
-rwxrwxr-x. 1 amd amd 20120 Sep 4 13:37 libfoo.so.1.0.2
rerun main
foo doimpl 10 version 1 foo
foo doimpl 20 version 1 foo
bar doimpl 20 version 1 bar
it worked but did not use updated libfoo version 2
update libfoo.so.1 soname link to point to lated
cd lib.so; rm libfoo.so.1; ln -s libfoo.so.1.0.2 libfoo.so.1; cd ..
ls -l lib.so
total 60
lrwxrwxrwx. 1 amd amd 11 Sep 4 13:34 libbar.so -> libbar.so.1
lrwxrwxrwx. 1 amd amd 15 Sep 4 13:34 libbar.so.1 -> libbar.so.1.0.0
-rwxrwxr-x. 1 amd amd 20160 Sep 4 13:31 libbar.so.1.0.0
lrwxrwxrwx. 1 amd amd 11 Sep 4 13:30 libfoo.so -> libfoo.so.1
lrwxrwxrwx. 1 amd amd 15 Sep 4 13:39 libfoo.so.1 -> libfoo.so.1.0.2
-rwxrwxr-x. 1 amd amd 20120 Sep 4 13:29 libfoo.so.1.0.0
-rwxrwxr-x. 1 amd amd 20120 Sep 4 13:37 libfoo.so.1.0.2
rerun main - does it pick new libfoo
LD_LIBRARY_PATH=lib.so ./main
foo 2 doimpl 10 version 2 foo
foo 2 doimpl 20 version 2 foo
bar doimpl 20 version 1 bar
yes foo 2
no need to rebuild libbar or main with updated libfoo as it was compatible