18

I want to move my current project to C++11. The code all compiles using clang++ -std=c++0x. That is the easy part :-) . The difficult part is dealing with external libraries. One cannot rely on linking one's C++11 objects with external libraries that were not compiled with c++11 (see http://gcc.gnu.org/wiki/Cxx11AbiCompatibility). Boost, for example, certainly needs re-building (Why can't clang with libc++ in c++0x mode link this boost::program_options example?). I have source for all of the external libraries I use, so I can (with some pain) theoretically re-build these libs with C++11. However, that still leaves me with some problems:

Developing in a mixed C++03/C++11 environment: I have some old projects using C++03 that require occasional maintenance. Of course, I'll want to link these with existing versions of external libraries. But for my current (and new) projects, I want to link with my re-built C++11 versions of the libraries. How do I organise my development environments (currently Ubuntu 12.04 and Mac OS X 10.7) to cope with this?

I'm assuming that this problem will be faced by many developers. It's not going to go away, but I haven't found a recommended and generally approved solution.

Deployment: Currently, I deploy to Ubuntu 12.04 LTS servers in the cloud. Experience leads one to depend (where possible) on the standard packages (e.g. libboost) available with the linux distribution. If I move my current project to c++11, my understanding is that I will have to build my own versions of the external libraries I use. My guess is that at some point this will change, and their will be 'standard' versions of library packages with C++11 compatibility. Does anyone have any idea when one might expect that to happen? And presumably this will also require a standard solution to the problem mentioned above - concurrent existence of C++03 libs and C++11 libs on the same platform.

I am hoping that I've missed something basic so that these perceived problems disappear in a puff of appropriate information! Am I trying to move to C++11 too soon?

Update(2013-09-11): Related discussion for macports: https://lists.macosforge.org/pipermail/macports-users/2013-September/033383.html

Community
  • 1
  • 1
Matt Wallis
  • 873
  • 5
  • 25
  • 3
    "How do I organise my development environments ... to cope with this?" -- adjust your build mechanism to pass different library paths; for Clang and GCC, `-L` is your friend. – Xeo Feb 20 '13 at 13:21
  • @Zeo, I am familiar with -L. I don't understand why making Clang have a different library path to GCC solves the problem. Perhaps you could elaborate? If I need to create my own process for marshalling different builds of 'standard' external libraries into different directories (probably one for C++11, one for C++03, and one for libs that works with both), then I'm in a place I'd rather avoid, and one that I would be sharing with zillions of developers inventing (minor variations of) the same wheel. Is that how it's going to be? – Matt Wallis Feb 20 '13 at 14:22
  • So... you compile with clang but use gcc ABI documentation? :) –  Feb 20 '13 at 20:09
  • 1
    Vlad, I don't use ABI docs at all for my own development, preferring to stick to the API :-) . The link to gcc ABI documentation is there to illustrate in some detail the nature of the incompatibility. This type of incompatibility is not compiler-specific. My question is not compiler-specific. – Matt Wallis Feb 21 '13 at 10:28

1 Answers1

1

You should use your configure toolchain (e.g. autotools) to "properly" configure your build for your target deployment. Your configuration tests should check for ABI compatible C++11 binaries and instruct the linker to use them first if detected. If not, optionally fail or fallback to a C++03 build.

As for C++11 3rd part libraries installed in a separate parallel directory tree, this isn't strictly necessary. Library versioning has been around for a long time and allows you to place different versions side by side on the system or wherever you'd like, again based on configure.

This might seem messy, but configure toolchains were designed to handle these messes.

Andy
  • 1,663
  • 10
  • 17
  • these sound like the right tools for the job. How does one "check for ABI compatible C++11 binaries?". With different versions (C++03, C++11) versions of external libs in the same dir, can one similarly check both for ABI compatibility? Or does one need to, for example, set up symbolic links that match the -l linker option? – Matt Wallis Mar 02 '13 at 14:53
  • Yes, it seems messy! Too messy for me to attempt at present (I've always found autoconf scary!) unless I can copy what someone else who is more familiar with the tools has done. – Matt Wallis Mar 02 '13 at 15:07