$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-users] can different versions of boost coexist in an executable?
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2012-09-04 19:41:08
Hello,
I am developing a C++ library, which I distribute in binary form as a
static library. 
The implementation of my library uses Boost, but the interface does not,
so I completely shield my users from the Boost dependency by linking
the Boost object files that my implementation requires into the static
library.
Suppose a client of my library uses Boost in their own code. When they 
link their executable, the linker now sees two copies of some Boost 
libraries: the copy in my static library, and their own copy that they 
are linking. It seems that the linker only keeps one of the two and 
discards the other.
If the Boost version that I linked into my static library is different 
from the Boost version my client uses, then one of my code and their
code will be linked to a different version of Boost that the one it
was compiled against, leading to a crash.
I suppose one way to rectify this problem would be for me to document
what version of Boost libraries I compiled and linked against, and 
require that if my clients use Boost themselves, they use the same 
version. However, I dislike this solution for two reasons:
  1) It exposes my library's dependence on Boost, which was meant to
     be an implementation detail.
  2) It limits my clients to using a particular version of Boost.
     They may have good reasons for using an older (or newer!) version
     instead.
I would much prefer if the linker kept both copies of the Boost libraries
in the executable, and each piece of code (mine and my client's) used
whichever version of the libraries it was compiled against. 
Can this be accomplished?
Thanks,
Nate