Using Clang instead of GCC: Difference between revisions
imported>Artturin add replaceStdenv |
imported>Widlarizer Clang is not a C++ compiler |
||
| Line 1: | Line 1: | ||
You can use Clang instead of GCC as a compiler for any package by overriding <code>stdenv</code>, which contains the compilation toolchain, with: | You can use Clang instead of GCC as a C compiler for any package by overriding <code>stdenv</code>, which contains the compilation toolchain, with: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
stdenv = pkgs.clangStdenv; | stdenv = pkgs.clangStdenv; | ||
| Line 10: | Line 10: | ||
Depending on the case you may want to set this value in different location, and using different mechanism. | Depending on the case you may want to set this value in different location, and using different mechanism. | ||
Unlike <code>gcc</code>, you can not use the <code>clang</code> command to compile C++. You must use the <code>clang++</code> command. Using clang to compile C++ will likely result in "fatal error: ... file not found" errors on standard library <code>#include</code> directives. This differs from Linux distributions like Debian and Arch Linux. If a project doesn't respect CXX and expects <code>clang</code> to compile C++, it will fail to build. | |||
== Globally, in a package repository tree == | == Globally, in a package repository tree == | ||