Should I use libc++ or libstdc++?
I would use the native library for each OS i.e. libstdc++ on GNU/Linux and libc++ on Mac OS X.
libc++ is not 100% complete on GNU/Linux, and there's no real advantage to using it when libstdc++ is more complete. Also, if you want to link to any other libraries written in C++ they will almost certainly have been built with libstdc++ so you'll need to link with that too to use them.
More info here about the completeness of libc++ on various platforms.
libc++ vs libstdc++ std::is_move_assignable: Which is the most correct?
For anything referenceable, the two implementations do the same thing, since the extraneous const
in libc++ is meaningless but also harmless.
(Judging from the diff, it certainly looks like temporary insanity to me :) Seems to be a C&P issue from a (wrong) implementation of is_copy_assignable
.)
For anything non-referenceable (i.e., cv void
or abominable function types), libstdc++ returns false_type
.
In libc++, add_{l,r}value_reference
returns it unchanged (this depends on an issue resolution that postdates C++14). Sprinkling a const
on top does nothing for AFTs and adds a const
for the void
y types.
We then go to is_assignable
, which SFINAE-tests the well-formedness of declval<T>() = declval<U>()
, for either T == U == some AFT
or T == some void type
and U = some const-qualified void type
. In all cases the expression is ill-formed (in a SFINAE-friendly manner), so we get false_type
back.
The two are equivalent.
When is it necessary to use the flag -stdlib=libstdc++?
On Linux: In general, all commonly available linux distributions will use libstdc++ by default, and all modern versions of GCC come with a libstdc++ that supports C++11. If you want to compile c++11 code here, use one of:
g++ -std=c++11 input.cxx -o a.out
(usually GNU compiler)g++ -std=gnu++11 input.cxx -o a.out
On OS X before Mavericks: g++
was actually an alias for clang++
and Apple's old version of libstdc++ was the default. You could use libc++ (which included c++11 library support) by passing -stdlib=libc++
. If you want to compile c++11 code here, use one of:
g++ -std=c++11 -stdlib=libc++ input.cxx -o a.out
(clang, not GNU compiler!)g++ -std=gnu++11 -stdlib=libc++ input.cxx -o a.out
(clang, not GNU compiler!)clang++ -std=c++11 -stdlib=libc++ input.cxx -o a.out
clang++ -std=gnu++11 -stdlib=libc++ input.cxx -o a.out
On OS X since Mavericks: libc++ is the default and you should not pass any -stdlib=<...>
flag. Since Xcode 10, building against libstdc++ is not supported at all anymore. Existing code built against libstdc++ will keep working because libstdc++.6.dylib
is still provided, but compiling new code against libstdc++ is not supported.
clang++ -std=c++11 input.cxx -o a.out
clang++ -std=gnu++11 input.cxx -o a.out
Cmake differentiate between libc++ and libstdc++
Something like this should work:
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
When/why are libstdc++ and libc++ symbols incompatible?
So, is the problem
std::allocator<char>
?
What? No. It's everything in your example.
The doc you quoted clearly says the goal is compatibility for "low-level features such as exception objects, rtti and memory allocation".
std::set
and std::string
are not "low-level features such as exception objects, rtti and memory allocation". They are very definitely not compatible between libc++ and libstdc++, which are completely different libraries with completely different implementations.
The compatible pieces are things like std::type_info
and std::exception
(and the derived exception types in <stdexcept>
) because those are part of the basic language runtime. Anything above that, such as containers, strings, algorithms, I/O, locales etc. is not compatible.
how to use libc++ and libstdc++ for different libraries in one project
Do not do this!
Why?
- depending on the name mangling scheme used it might not even be possible because
libc++
is going to have the same symbols aslibstdc++
- if there are no symbol collisions you are probably going to run into undefined behavior when you take objects from one library and mix them with objects/functions from the other.
class
structures will not be compatible. Internal class structures will be implemented or laid out differently.libstdc++
is no longer available on iOS 12. Your program will not run on it.- The correct way to fix your problem is to download/compile updated versions of your libraries. Period.
Related Topics
How Would One Disable Nagle's Algorithm in Linux
The Concept of 'Hold Space' and 'Pattern Space' in Sed
Linux: Remove File Extensions for Multiple Files
Extract Lines Between Two Patterns from a File
Count Number of Files Within a Directory in Linux
Why Doesn't "Total" from Ls -L Add Up to Total File Sizes Listed
Do I Need -D_Reentrant with -Pthreads
Initial State of Program Registers and Stack on Linux Arm
Linux Equivalent of the MAC Os X "Open" Command
Relinking an Anonymous (Unlinked But Open) File
How to Search for Files Containing Dos Line Endings (Crlf) with Grep on Linux
Why Is the Page Size of Linux (X86) 4 Kb, How Is That Calculated
Prevent File Descriptors Inheritance During Linux Fork
Efficiently Test If a Port Is Open on Linux
A General Linux File Permissions Question: Apache and Wordpress