4 ms·
Unlike in C, in C++ it is not possible to use an independent implementation of the standard library. Clang is compatible with GCC's standard library/libstdc++
by Maxatar 2y ago
Unlike in C, in C++ it is not possible to use an independent implementation of the standard library.
Clang is compatible with GCC's standard library/libstdc++ and MSVC's standard library because the clang compiler explicitly supports them, but it's not possible to use clang's standard library with GCC in a standard conforming way or interchange GCC's with MSVC's standard library.
There are some hacks that let you use some parts of libc++ with GCC by using the nostdlib flag, but this disables a lot of C++ functionality such as exception handling, RTTI, type traits. These features are in turn used by things like std::vector, std::map, etc... so you won't be able to use those classes either, and so on so forth...
- gumby 2y ago> Unlike in C, in C++ it is not possible to use an independent implementation of the standard library. It sure is, and is pretty easy to do. I know companies using EASTL, libcu++, and HPX, as well as more who use Folly and Abseil which have alternate implementations to much of the standard library. These days many languages have a single implementation so some people whose experience is only in those environment complain that C++ is “unnecessary complicated to use”. But a lot of that flexibility and back compatibility is what allows these multiple implementations to thrive while representing different points in the design/feature space.
- Maxatar 2y agoNone of those are implementations of the C++ standard library. None of them even live in the same namespace as the standard library so your claim that they remain compatible at the source level is nonsense. Just a simple Google search would reveal that you are wrong about this and what's worse is that you place the burden on me to have to disprove your wrong assertions as opposed to providing references that justify your position: Folly https://github.com/facebook/folly https://github.com/facebook/folly: "It complements (as opposed to competing against) offerings such as Boost and of course std. In fact, we embark on defining our own component only when something we need is either not available, or does not meet the needed performance profile." libcu++: https://nvidia.github.io/cccl/libcudacxx/ https://nvidia.github.io/cccl/libcudacxx/ "It does not replace the Standard Library provided by your host compiler (aka anything in std::) Incremental: It does not provide a complete C++ Standard Library implementation." Abseil: https://github.com/abseil/abseil-cpp https://github.com/abseil/abseil-cpp "Abseil is an open-source collection of C++ library code designed to augment the C++ standard library. Abseil is not meant to be a competitor to the standard library"
- gumby 2y ago> Just a simple Google search would reveal that you are wrong about this and what's worse is that you place the burden on me to have to disprove your wrong assertions as opposed to providing references that justify your position: How rude. Have you used any of those libraries or perhaps relied on Google's "AI"-generated answer? > None of those are implementations of the C++ standard library. HPX, EASTL specifically are, the latter being heavily used in (unsurprisingly) the gaming comunity). libcu++ is for your target compilation. As for Folly and Abseil, I wrote "as well as more who use Folly and Abseil which have alternate implementations to much of the standard library" (i.e. not ful drop in replacements). So really I don't know what your point is: you made an assertion, then replied not to what I actually wrote but by simply doing a quick google search and using that as your conclusion. I have used all of HPX, Folly and Abseil but I guess the top of a google search result is more authoritative.
- Maxatar 2y agoMy point is simple, you are poorly informed on this topic and should refrain from speaking about it. None of the libraries you listed are independent implementations of the standard library let alone source compatible. EASTL does not claim to be an implementation of the C++ standard library, its claim is that it is an alternative to the C++ standard library. Perhaps the distinction is too subtle for you to have actually understood it but one thing is obvious, you have clearly never used it.
- gpderetta 2y agoI'm pretty sure that gumby forgot more about c++ and c++ implementations than the rest of us will ever know.
- account42 2y agoEASTL is not a C++ standard library implementation even if it's design does follow it in parts.
- pjmlp 2y agoAs proven by musl versus glibc issues, that possibility is mostly theoric, with plenty of gotchas in practice.
- lmz 2y agoWhich musl issues are to do with GCC? Alternate C libraries are common on Linux e.g. uclibc, dietlibc, bionic... Not to mention also the other OSs GCC runs on that don't use glibc. Of course, mixing C libraries between the main executable and libraries probably won't work.
- pjmlp 2y agoAs there are common people on forums searching for problems with their C code crashing and burning, because while those libraries conform to ISO C standard, their implementation defined semantics aren't the same.
- lmz 2y agoBut the original post's meaning of "independent" runtime library was "compiler independent" (vs C++). Not that there was no difference between the C libraries.
- pjmlp 2y agoIf there is a difference, it is no longer independent.
- lmz 2y agoThis makes no sense. As I said the original poster was saying that g++ and libstdc++ are tangled together and it is not possible to use g++ with another implementation of the C++ libraries. But you can use gcc with other C libraries. As proven by gcc running on other OSs with non glibc libraries. If anything isn't "independent" here (using your definition) it's the apps that rely on implementation detail - not the C library, the C programming language, or the compiler.
- account42 2y ago> but it's not possible to use clang's standard library with GCC Of course it is. Both libc++ and GCC do make the effort to keep that compatibility going. > in a standard conforming way What is that supposed to mean here? GCC doesn't let you simply specify -stdlib=libc++ but while it's unfortunate it just means that you have to use -nostdlib++ and add the libc++ include and linking flags manually. > There are some hacks that let you use some parts of libc++ with GCC by using the nostdlib flag, but this disables a lot of C++ functionality such as exception handling, RTTI, type traits. These features are in turn used by things like std::vector, std::map, etc... so you won't be able to use those classes either, and so on so forth... -nostdlib++ is not a hack but the documented way for using a different standard library implementation. This doesn't prevent you from using exceptions and other runtime functionality.