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.outclang++ -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.outclang++ -std=gnu++11 input.cxx -o a.out
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.outclang++ -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.outclang++ -std=gnu++11 input.cxx -o a.out
When is it necessary to use use the flag
-stdlib=libstdc++for the compiler and linker when compiling with gcc?
Short answer: never
Longer answer: -stdlib is a Clang flag and will not work with any version of GCC ever released. On macOS sometimes the gcc and g++ commands are actually aliases for Clang not GCC, and the version of libstdc++ that Apple ships is ancient (circa 2008) so of course it doesn't support C++11. This means that on macOS when using Clang-pretending-to-be-GCC, you can use -stdlib=libc++ to select Clang's new C++11-compatible library, or you can use -stdlib=libstdc++ to select the pre-C++11 antique version of libstdc++ that belongs in a museum. But on GNU/Linux gcc and g++ really are GCC not Clang, and so the -stdlib option won't work at all.
Edit: Since I wrote this answer, GCC was changed to conditionally support the -stdlib flag, but for most platforms that support is disabled by default. Even when it's enabled, the default is -stdlib=libstdc++ so you still never need to say that explicitly. GCC will still automatically use libstdc++.
Does the compiler automatically use libstdc++?
Yes, GCC always uses libstdc++ unless you tell it to use no standard library at all with the -nostdlib or -nostdlib++ option (in which case you either need to avoid using any standard library features, or use -I and -L and -l flags to point it to an alternative set of header and library files).
I am using gcc4.8.2 on Ubuntu 13.10 and I would like to use the c++11 standard. I already pass
-std=c++11to the compiler.
You don't need to do anything else. GCC comes with its own implementation of the C++ standard library (libstdc++) which is developed and tested alongside GCC itself so the version of GCC and the version of libstdc++ are 100% compatible. If you compile with -std=c++11 then that enables the C++11 features in g++ compiler and also the C++11 features in the libstdc++ headers.
Installing Spacy on Mac - "gcc: error: unrecognized command line option '-stdlib=libc++'"
gcc - Specify which libstdc++ to use - Unix & Linux Stack Exchange
Unrecognized command line option '-stdlib=libc++ for certain root gcc combinations on MAC
Unintended Consequences of Supporting -stdlib=libc++
Videos
As the error message says, the gcc compiler has no such commandline option as -stdlib. The LLVM clang compiler does.
That is because clang offers you the choice of linking the LLVM standard C++ library (libc++) or the
GNU standard C++ library (libstdc++), whereas gcc supports only libstdc++.
Delete the option -stdlib=libc++. You might as well also replace -std=c++0x with -std=c++11,
since the former denotes experimental support for the 2011 C++11 standard, applicable for gcc versions
4.3 through 4.6.
It might also be useful to install the clang/clang++ compiler and use this when it comes to the build step (because you are likely to run into gcc issues with other Python packages):
python configure.py
export CC=/usr/bin/clang
export CXX=/usr/bin/clang++
python setup.py build
make -j 4
python setup.py install
cd ../
python -c "import pyopencl"
today I noticed that clang pulls gcc as a dependency during installation. Does anyone know why? I thought clang was an independent compiler. is this an oddity of a particular distribution, or does clang actually use some parts of gcc?
Can someone elaborate on what are libc, libc++, libstdc++
-
What the difference between libc++ and libstdc++? Why can't we just use one of them for all times?
-
How to determine which versions of these libs support specific standard version? For example which version of c++ standard does libstdc++-4.6 support?
-
Can i just "copy-paste" these libs into target OS to run my project if that OS lacks newer versions of these ones available in repositories?
-
Can i just "copy-paste" all dependent `.so` files into target OS? What should i consider when "copy-pasting" libraries from my development workstation to user's one?
-