0

I am using GCC to compile a C++ application on Ubuntu 13. I want to be able to use C++11 features in my code, but at the same time still be able to produce a binary that my users can run on older versions of Ubuntu.

If I compile on Ubuntu 13 with the latest version of GCC my binary will not run on Ubuntu 12 since glibc is not forward compatible: (How compatible are different versions of glibc?)

  • What are my options?

  • Is this even possible without requiring my users to jump through massive hoops?

  • If not, what do my users have to do to be able to run the binary (i.e. can they install the newer glibc on the older version of Ubuntu)?

Note: I don't not want to consider statically linking glibc since:

  1. I've read that this is a very bad idea
  2. Licensing issues
  3. Cross-distribution compatibility issues

Currently my application does not use any C++11 features and I compile on an older version of Ubuntu with an older version of GCC to avoid this problem. But it makes me sad not being able to use the latest and greatest language features :(

Community
  • 1
  • 1
pqvst
  • 4,344
  • 6
  • 33
  • 42
  • Link statically. Licensing issues are going to exist either way, and a statically compiled program -- because it includes everything it needs, rather than relying on the end user's libs -- will work on basically any Linux system that uses the same CPU. – cHao Nov 21 '13 at 20:32
  • Just compile with a newer gcc on an older OS. Install gcc from sources or from a manually added repository. You may have to link with libstdc++ statically though, or distribute a copy of libstdc++ with your program (I think it's legal, if you also ship libstdc++ sources; IANAL, check with your legal department). – n. m. could be an AI Nov 21 '13 at 20:38
  • 1
    @cHao, I've read a lot of SO questions regarding statically linking glibc, and many seem to indicate that this is a bad idea. For example (http://stackoverflow.com/a/11654451/966782). Also, LGPL with regards to statically linking scares me. I'd like to avoid it... – pqvst Nov 21 '13 at 21:31

3 Answers3

1

You can try to use Boost Libraries which have quite the same features as C++11 and is "more retro-compatible" than C++11 : it will easily compile on older version of Ubuntu.

Otherwise the best option might be to ask to the users of Ubuntu 12.04 to upgrade there GCC from 4.6 to 4.7 or more recent : http://www.swiftsoftwaregroup.com/upgrade-gcc-4-7-ubuntu-12-04/

doizuc
  • 408
  • 5
  • 11
0

You are asking "how do I use code that isn't on older systems".

The answer is of course, "Include the code with your project".

If you think through what you're asking, you'll realize that in any case, you'll need the code for the c++11 functions in libstdc++. So if they aren't on ubuntu 12, YOU have to add them. Therefore, you'd have to have it statically linked. it's the only way to ensure it will run on an arbitrary ubuntu12 system.

Well you could make a fancy installation, but in the end, it'd just be your apps "dynamically linking" to the libstdc++, so it may as well be statically linked, since no other program is going to be looking for it on ubuntu12

AwokeKnowing
  • 7,728
  • 9
  • 36
  • 47
0

In general, a c++ library is compatible only if the same compiler is used and (!) the versions of the compilers are matching (you might be lucky, though). There is no way to be portable in this sense, besides writing C-code.