Test linux linking the next situation: two libraries depends on different versions third library.
This code based on this stackoverflow answer. dlopen-variant is based on this stackoverflow answer.
main_A.exe ───┮━━━> libA ━━━━> libC.v1
│
main_AB.exe ──┤
│
main_B.exe ───┶━━━> libB ━━━━> libC.v2
You can choose compiler by setting CC environment. For using GCC:
export CC=gcc
For using Clang:
export CC=clang
Build:
mkdir build && cd build
cmake ..
cmake --build .
Run tests using Linux:
for i in ./main_A.* ./main_B.* ./main_AB.*; do echo "$i:"; LD_LIBRARY_PATH=./A:./B:$LD_LIBRARY_PATH $i; done
Run tests using Mac:
for i in ./main_A.* ./main_B.* ./main_AB.*; do echo "$i:"; DYLD_LIBRARY_PATH=./A:./B:$DYLD_LIBRARY_PATH $i; done
Ubuntu 16.04.02, CentOS 7.3: result the same for both GCC and Clang:
./main_A.shared:
main_A->call_A->call_C (v1)
./main_A.static:
main_A->call_A->call_C (v1)
./main_B.shared:
main_B->call_B->call_C (v2)
./main_B.static:
main_B->call_B->call_C (v2)
./main_AB.dlopen:
main_AB->call_A->call_C (v1) # <- correct
main_AB->call_B->call_C (v2) # <- correct
./main_AB.shared:
main_AB->call_A->call_C (v1) # <- correct
main_AB->call_B->call_C (v1) # <- wrong
./main_AB.static:
main_AB->call_A->call_C (v1) # <- correct
main_AB->call_B->call_C (v1) # <- wrong
MacOSX El Capitan 10.11.6, result same for both GCC and Clang:
./main_A.shared:
main_A->call_A->call_C (v1)
./main_A.static:
main_A->call_A->call_C (v1)
./main_B.shared:
main_B->call_B->call_C (v2)
./main_B.static:
main_B->call_B->call_C (v2)
./main_AB.dlopen:
main_AB->call_A->call_C (v1) # <- correct
main_AB->call_B->call_C (v2) # <- correct
./main_AB.shared:
main_AB->call_A->call_C (v1) # <- correct
main_AB->call_B->call_C (v2) # <- correct
./main_AB.static:
main_AB->call_A->call_C (v1) # <- correct
main_AB->call_B->call_C (v1) # <- wrong