-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working variant of diamond_dependency_1.sh
The trick is done by using versioned symbols in libcommon. Well, this opens the next door towards dependency 'heaven' :)
- Loading branch information
Showing
1 changed file
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#! /bin/bash | ||
|
||
# case 1: | ||
# | ||
# main -----------------> libcommon | ||
# \--- libmiddle ---> libcommon | ||
# | ||
# Now use versioned symbols, and tell libmiddle about libcommon | ||
# | ||
# 1) update libcommon | ||
# 2) rebuild libmiddle | ||
# | ||
# result: libmiddle uses new API | ||
|
||
set -e | ||
|
||
# install libcommon API 1 | ||
|
||
cat >libcommon.c <<"_EOF_" | ||
#include <stdio.h> | ||
void libcommon_test(char *caller) { | ||
printf("libcommon_test V1 called by %s\n",caller); | ||
} | ||
_EOF_ | ||
cat >libcommon.h <<'_EOF_' | ||
#define API_VERSION "1" | ||
_EOF_ | ||
cat >v1.lds <<'_EOF_' | ||
VER_1 { global: libcommon_test; }; | ||
_EOF_ | ||
gcc -shared -fPIC -Wl,-soname=libcommon-1.so,--version-script=v1.lds -o libcommon-1.so libcommon.c | ||
ln -sf libcommon-1.so libcommon.so | ||
|
||
# install libmiddle | ||
|
||
cat >libmiddle.c <<_EOF_ | ||
#include <stdio.h> | ||
#include "libcommon.h" | ||
extern void libcommon_test(char *caller); | ||
void libmiddle_test(char *caller) { | ||
printf("libmiddle_test called by %s\n",caller); | ||
libcommon_test("libmiddle expecting V" API_VERSION " API"); | ||
} | ||
_EOF_ | ||
gcc -shared -fPIC -Wl,-soname=libmiddle-1.so -o libmiddle-1.so libmiddle.c | ||
ln -sf libmiddle-1.so libmiddle.so | ||
|
||
# install main | ||
|
||
cat >main.c <<_EOF_ | ||
#include <stdio.h> | ||
#include "libcommon.h" | ||
extern void libcommon_test(char *caller); | ||
extern void libmiddle_test(char *caller); | ||
int main() { | ||
libmiddle_test("main"); | ||
libcommon_test("main expecting V" API_VERSION " API"); | ||
} | ||
_EOF_ | ||
|
||
gcc -o main -Wl,-rpath=. -lmiddle -L. -lcommon main.c | ||
|
||
echo "########### run main" | ||
|
||
./main | ||
|
||
echo "########### update libcommon" | ||
|
||
cat >libcommon.c <<"_EOF_" | ||
#include <stdio.h> | ||
void libcommon_test(char *caller) { | ||
printf("libcommon_test V2 called by %s\n",caller); | ||
} | ||
_EOF_ | ||
cat >libcommon.h <<'_EOF_' | ||
#define API_VERSION "2" | ||
_EOF_ | ||
cat >v2.lds <<'_EOF_' | ||
VER_2 { global: libcommon_test; }; | ||
_EOF_ | ||
gcc -shared -fPIC -Wl,-soname=libcommon-2.so,--version-script=v2.lds -o libcommon-2.so libcommon.c | ||
ln -sf libcommon-2.so libcommon.so | ||
|
||
echo "########### run main" | ||
|
||
./main | ||
|
||
echo "########### rebuild libmiddle" | ||
|
||
gcc -shared -fPIC -Wl,-soname=libmiddle-1.so -o libmiddle-1.so libmiddle.c -L. -lcommon # better: -lcommon-2 | ||
ln -sf libmiddle-1.so libmiddle.so | ||
|
||
echo "########### run main" | ||
|
||
./main |