3

I need to build a C++17 application with distro having libstdc++ 6.0.22 (GLIBCXX 3.4.22) and libc 2.24. These versions of libraries don't allow me to build modern c++ and I cannot update system's versions. In fact, I need a correct working application (may be carrying compiled stdlib from sources with it) that I could give to my clients and they would work with it. The distro has llvm-9 in its repos and that provides a standard library I could use

I tried 2 things:

  1. To build the app against libc++ but that will force me to recompile system dependencies too and distribute them with my package as well (but i don't even have an idea how to do that)
  2. To build libstdc++ from sources and distribute it with my package

The (1) approach took too much time to compile and I need to know how do I recompile system dependencies and distribute them. It is not a small hello world application, it uses a lot of system deps
The (2) approach I just tried and failed because of a lot of errors (unknown type, unexpected identifier, etc..)

IC_
  • 1,624
  • 1
  • 23
  • 57

1 Answers1

3

libstdc++ is a part of the C++ compiler (gcc or llvm). You need not only the current libstdc++ but also the compiler that goes with it. The current version of each compiler (which is needed for support C++17) requires the current version of libstdc++ for programs that are compiled with it. I haven't double-checked the binutils dependencies, but the newer compilers will likely require a newer version of binutils (and, specifically, the ld linker). The advanced features of the new C++ standards likely required new functionality implemented in the system linker. Not to mention the new compiler functionality as well (link-time optimizations in the curren version of gcc, for example, require closely tied support from the linker, ld, or gold, which will actually invoke the compiler again during the link phase).

Your only realistic solution is to bootstrap a secondary toolchain, starting with binutils, and then finally with the current version of your compiler. You do not have have to update or replace your system-installed libstdc++, or compiler, or ld. By running their respective configuration scripts it's possible to install the entire toolchain in a separate directory hierarchy so that they will not interfere with your system-installed binutils and compiler.

As far as other system dependencies go, you probably need to rebuild only the C++ ones. System dependencies that are C libraries are unlikely to need a rebuild. Still, if you have some, you will have to rebuild them, that's just the way it is, there are no alternative shortcuts.

That's pretty much it. There are no other alternatives. As you can surmise, bootstrapping an entire toolchain in order to "side-load it" onto a system with an existing compiler toolchain, in a manner as to not interfere with it, is not a small endeavour. It's a challenge even for skilled, experienced developers or system administrators. But this is certainly doable, I've done this a few years ago, in a previous job. It was possible to do that, so I see no reason why it's not possible to do it now; and this is pretty much the only feasible way to be able to support a modern version of C++ on a distribution that comes with an older compiler tolchain (that does not support the current C++ standard).

Sam Varshavchik
  • 114,536
  • 5
  • 94
  • 148
  • What do you mean by "bootstrap a secondary toolchain, starting with binutils"? Compiler will still use system headers, libraries, linker, etc.., won't it? – IC_ Feb 19 '21 at 03:54
  • The system C headers, yes. But the compiler will use its own C++ headers (from its own version of libstdc++), and binutils. When you tell your compiler to compile and link your code the compiler will invoke the linker on your behalf, and tell it where to find libstdc++ so that your actual code will, actually, link correctly. As I explained, the new version of the compiler is unlikely to work with your existing linker. You will need to install a new version of binutils. There might also other dependencies that need to be side-loaded as well. All the requisite info is in their installation docs. – Sam Varshavchik Feb 19 '21 at 03:57
  • It is probably easier to give the clients a complete VM to run this application... – U. W. Feb 19 '21 at 11:27
  • 1
    @U.W. that is not a way they would want it. Our client is a quite big company with their own limitations and restrictions. Giving them an environment is not an elegant solution at all – IC_ Feb 19 '21 at 17:48