How to install clang++ on osx?

16,491

Solution 1

I suspect all you were missing was libstdc++ but trying to figure that out without seeing your build log is impossible. Especially as you say 'after installation...' when there's no installation step in the instructions you link to, only build?

So, I'm going to suggest you use brew to do the install along with the dependencies. llvm35 is a bit bleeding edge but the current instructions that install that with brew are:

Step 1: make sure you have a recent enough gcc/libc to build clang (may not be necessary for you):

$ brew install gcc47 

Step 2: install the HEAD version of llvm35 with all the trimmings (see https://github.com/Homebrew/homebrew-versions/issues/340 - you MUST read this, because we are building HEAD versions the instructions might be updated tomorrow. Correct just now, I just built it!):

$ brew install isl --HEAD
$ brew install --cc=gcc-4.7 --HEAD llvm35 --with-asan --with-clang --with-libcxx --rtti --all-targets
# wait....
🍺  /usr/local/Cellar/llvm35/HEAD: 1427 files, 240M, built in 18.3 minutes

$ /usr/local/Cellar/llvm35/HEAD/bin/clang++-3.5 -v
clang version 3.5 
Target: x86_64-apple-darwin12.5.0
Thread model: posix

Note my command differs from the one in the link by including --cc=gcc-4.7 to use the gcc installed in step 1; if your gcc is already good enough, you won't need that. This is installed keg-only so won't be in the usual paths (see: https://github.com/Homebrew/homebrew/wiki/FAQ, by 'Cellar' they mean /usr/local/Cellar; I've shown the path mine built above)

Solution 2

As of now you can just do

brew install llvm

For me this installed llvm and clang 4.0.0 to /usr/local/opt/llvm

Share:
16,491
rdo
Author by

rdo

Interested in java/kotlin, golang, rust.

Updated on June 15, 2022

Comments

  • rdo
    rdo over 1 year

    I've have got a default clang and clang++ in /usr/bin/ directory. Both of them have 3.3 version.

    Also I've installed clang with help of this specification. After installation I've gotten additional binary utility clang-3.5. But clang++-3.5 was not installed. How to install it?

  • rdo
    rdo over 9 years
    What do you mean missing libstdc++? Is it an additional option for configure script or make command?
  • bazzargh
    bazzargh over 9 years
    I was referring to the instructions you linked to, step 7. As I said, I'm not going to get into the game of guessing what you've done wrong without seeing a log, but if your build did create clang++ and you've just mislaid it, you'll find a line like "> llvm[4]: ======= Finished Creating Debug+Asserts Alias clang++" in your log.
  • Ian Vaughan
    Ian Vaughan over 1 year
    Didnt work for me, trying to asdf install python 3.6.2 checking for --with-cxx-main=<compiler>... no checking for clang++... no
  • Timmmm
    Timmmm over 1 year
    Yeah because you need to add it to your PATH.