3

I have built a library (VC10) that is dependant on multiple Boost libraries. I would like to use this library in multiple applications where each application is dependant on different Boost versions and I would like to be able to do this without building the library for each Boost version.

I have built my library using BOOST_ALL_DYN_LINK as well as using BOOST_ALL_NO_LIB but both these libraries seem to depend on a specific Boost version.

Could someone please explain how I can build a library that is dependant on Boost where it is possible to update the Boost version without recompiling or relinking the library?

UncleBlue
  • 265
  • 1
  • 2
  • 7
  • [Check this thread](http://stackoverflow.com/q/4736877/220636) perhaps it helps? – nabulke Apr 30 '12 at 08:20
  • Using BOOST_ALL_DYN_LINK (i.e. linking the DLLs at runtime) won't help because there could be different BOOST versions on the target system. You should consider providing a static library with the correct boost Libraries also statically linked to your lib project. – nabulke Apr 30 '12 at 08:28
  • Why would a statically linked boost version be better? I use for example the library Thread in boost with version A of boost and statically links this to my library. Then the application uses version B of boost Thread together with the library that uses version A. It seems to me like this could cause problems. – UncleBlue Apr 30 '12 at 09:04
  • If you statically link the boost thread library to your own lib, your lib is independent from any other locally available boost thread version at the user side - it already has all the code it needs. – nabulke Apr 30 '12 at 09:16
  • Is the library truly independent? The application and the library will use different implementation of boost libraries (different versions) which might cause problems when the library and the application communicates with each other. This is why I would like to use the boost version that is supplied by the application for both the lib and the application. – UncleBlue Apr 30 '12 at 09:27
  • Hmmm, I guess you are right. This could probably cause problems, depending on the interface of your library. Perhaps someone else can enlighten us with an answer. Would like to see one... :-) – nabulke Apr 30 '12 at 09:30
  • 3
    Is there a specific reason you have to use multiple versions of boost? This might not be the answer you are looking for, but adjusting your code to use a single version might save you a lot of headaches – Jim Jeffries Jun 23 '12 at 14:40

1 Answers1

1

"Could someone please explain how I can build a library that is dependant on Boost where it is possible to update the Boost version without recompiling or relinking the library?"

I do not think that this is possible. Any number of small changes, such as adding a new data member to a class, will require recompilation to switch between releases. It would only be possible if boost does not change any such details between releases.

If you are unable to follow @jamesj suggestion of sticking to a single version, namespaces may be able to help. I would take each boost version and modify it so instead of having boost as the top level namespace it would be boost_x_y_z where x y z gives the version number. So the following code

namespace acc = boost::accumulators;
typedef acc::features<acc::tag::density> features_t;
typedef acc::accumulator_set<double, features_t> accumulator_t;

Could target version 1.47.0 with:

namespace acc = boost_1_47_0::accumulators;
typedef acc::features<acc::tag::density> features_t;
typedef acc::accumulator_set<double, features_t> accumulator_t;

If you don't care what version you use you might put in a header somewhere:

namespace boost_latest = boost_1_50_0;

So my example would become:

namespace acc = boost_latest::accumulators;
typedef acc::features<acc::tag::density> features_t;
typedef acc::accumulator_set<double, features_t> accumulator_t;

Then when a new version comes along you just update a single definition and recompile. New versions of your library should still be ABI compatible with your old programs. But they will not take advantage of the new boost release without recompilation.

Bowie Owens
  • 2,798
  • 23
  • 20