- wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.8.2/gcc-4.8.2.tar.bz2
- tar -xvjf gcc-4.8.2.tar.bz2
- cd gcc-4.8.2
- ./contrib/download_prerequisites
- cd ..
- mkdir gcc-4.8.2-build
- cd gcc-4.8.2-build
- %PWD/../gcc-4.8.2/configure --prefix=$HOME/toolchains --enable-languages=c,c++
- make -j$(nproc)
- make install
-
-For more details, check out the `excellent GCC wiki entry
-<http://gcc.gnu.org/wiki/InstallingGCC>`, where I got most of this information
-from.
-
-Once you have a GCC toolchain, use it as your host compiler. Things should
-generally "just work". You may need to pass a special linker flag,
-``-Wl,-rpath,$HOME/toolchains/lib`` or some variant thereof to get things to
-find the libstdc++ DSO in this toolchain.
+ % wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.8.2/gcc-4.8.2.tar.bz2
+ % tar -xvjf gcc-4.8.2.tar.bz2
+ % cd gcc-4.8.2
+ % ./contrib/download_prerequisites
+ % cd ..
+ % mkdir gcc-4.8.2-build
+ % cd gcc-4.8.2-build
+ % $PWD/../gcc-4.8.2/configure --prefix=$HOME/toolchains --enable-languages=c,c++
+ % make -j$(nproc)
+ % make install
+
+For more details, check out the excellent `GCC wiki entry`_, where I got most
+of this information from.
+
+.. _GCC wiki entry:
+ http://gcc.gnu.org/wiki/InstallingGCC
+
+Once you have a GCC toolchain, configure your build of LLVM to use the new
+toolchain for your host compiler and C++ standard library. Because the new
+version of libstdc++ is not on the system library search path, you need to pass
+extra linker flags so that it can be found at link time (``-L``) and at runtime
+(``-rpath``). If you are using CMake, this invocation should produce working
+binaries:
+
+.. code-block:: console
+
+ % mkdir build
+ % cd build
+ % CC=$HOME/toolchains/bin/gcc CXX=$HOME/toolchains/bin/g++ \
+ cmake .. -DCMAKE_CXX_LINK_FLAGS="-Wl,-rpath,$HOME/toolchains/lib64 -L$HOME/toolchains/lib64"
+
+If you fail to set rpath, most LLVM binaries will fail on startup with a message
+from the loader similar to ``libstdc++.so.6: version `GLIBCXX_3.4.20' not
+found``. This means you need to tweak the -rpath linker flag.