How to install LLVM for Mac?
Remember to source .bash_profile
! I wasted a lot of time due to the silly problem.
homebrew does not link llvm
to /usr/local/bin
because it may conflict with the system one, causing all kinds of nasty bugs. Instead, you should use the full path to invoke them, such as /usr/local/opt/llvm/bin/lli
.
In fact there's a Caveat that's now listed which spells this out...
==> Caveats
==> llvmTo use the bundled libc++ please add the following
LDFLAGS
:LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"
llvm is keg-only, which means it was not symlinked into
/usr/local
, because macOS already provides this software and installing another version in parallel can cause all kinds of trouble.If you need to have llvm first in your PATH run:
echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.bash_profile
For compilers to find llvm you may need to set:
export LDFLAGS="-L/usr/local/opt/llvm/lib"
export CPPFLAGS="-I/usr/local/opt/llvm/include"
You can also add /usr/local/opt/llvm/bin/
to your $PATH environment variable:
echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
This way you can call other llvm
commands such as llvm-config
. A list of llvm can be found here.