views:

488

answers:

3

I'm looking to have two versions of BOOST compiled into a project at the same time. Ideally they should be usable along these lines:

boost_1_36_0::boost::shared_ptr<SomeClass> someClass = new SomeClass();
boost_1_35_0::boost::regex expression("[0-9]", boost_1_35_0::boost::regex_constants::basic);
A: 

You'll have a world of trouble linking because the mangled names will be different. And yes, I see you knew that, but it seems like it will be trouble all around.

Matt Price
That would be the point. I'd wrap all the regex source files in the boostv1 directory with namespace directives too.
Eclipse
See Daniel's point, the macros will be killer
Matt Price
+1  A: 

@Josh: While I agree with the shivering, I still believe this is the better course of action. Otherwise, linking troubles are a certainty. I've had the situation before where I had to hack the compiled libraries using objcopy to avoid definition conflicts. It was a nightmare for platform interoperability reasons because the name mangling works very differently even in different versions of the same compilers (in my case, GCC).

Konrad Rudolph
+6  A: 

I read (well scanned) through the development list discussion. There's no easy solution. To sum up:

  1. Wrapping header files in a namespace declaration

    namespace boost_1_36_0 {
        #include <boost_1_36_0/boost/regex.hpp>
    }
    namespace boost_1_35_0 {
        #include <boost_1_35_0/boost/shared_ptr.hpp>
    }
    
    • Requires modifying source files
    • Doesn't allow for both versions to be included in the same translation unit, due to the fact that macros do not respect namespaces.
  2. Defining boost before including headers

    #define boost boost_1_36_0
        #include <boost_1_36_0/boost/regex.hpp>
    #undef boost
    #define boost boost_1_35_0
        #include <boost_1_35_0/boost/shared_ptr.hpp>
    #undef boost
    
    • Source files can simply be compiled with -Dboost=boost_1_36_0
    • Still doesn't address macro conflicts in a single translation unit.
    • Some internal header file inclusions may be messed up, since this sort of thing does happen.

      #if defined(SOME_CONDITION)
      #  define HEADER <boost/some/header.hpp>
      #else
      #  define HEADER <boost/some/other/header.hpp>
      #endif
      

      But it may be easy enough to work around those cases.

  3. Modifying the entire boost library to replace namespace boost {..} with namespace boost_1_36_0 {...} and then providing a namespace alias. Replace all BOOST_XYZ macros and their uses with BOOST_1_36_0_XYZ macros.
    • This would likely work if you were willing to put into the effort.
Eclipse
If you're going to modify the headers, you might be able to avoid macro conflicts with something like 's/BOOST_/BOOST_1_36_0_/g'. Maybe.
Daniel James
I updated to note your suggestion.
Eclipse