Using Clang instead of GCC: Difference between revisions

imported>Widlarizer
Clang is not a C++ compiler
imported>Artturin
Undoing a edit because it's not exactly true and is because of a bug, linked the issue
 
Line 1: Line 1:
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:
You can use Clang instead of GCC as a 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.
Note you may get errors like <code>fatal error: ... file not found</code> on standard library <code>#include</code> directives, because of this bug https://github.com/NixOS/nixpkgs/issues/150655


== Globally, in a package repository tree ==
== Globally, in a package repository tree ==