Installing LLVM libraries along with Xcode

12,714

Solution 1

If you do not need to read LLVM implementation source code(such as in lib/tools directories) and might only play with libclang, perhaps using homebrew is enough for you.

brew install --with-clang --with-lld --with-python --HEAD llvm

Next you need to set PATH, CPLUS_INCLUDE_PATH and LD_LIBRARY_PATH. For me,

# export PATH=/usr/local/opt/llvm/bin:$PATH
# export CPLUS_INCLUDE_PATH=$(llvm-config --includedir):$CPLUS_INCLUDE_PATH 
# export LD_LIBRARY_PATH=$(llvm-config --libdir):$LD_LIBRARY_PATH 

You might configure the above information in your LLVM derived project with XCode.

However if you are also interested in Compiler-RT, Clang-Tools-Extra(see LLVM Download Page) you probably have to make LLVM as your XCode project (download from that page or via SVN as said in Getting Started with the LLVM System). After putting the sub-projects in proper directories, you can use XCode generator from CMake, the typical usage is:

cd YOUR_LLVM_SRC_ROOT
mkdir build
cd build
cmake -G Xcode ..

Use XCode to open the project file XXX.xcodeproj and it should build the project.

Solution 2

I tried brew install --with-clang --with-lld --with-python --HEAD llvm as suggested in the other answer, but it gave me an error:

Error: invalid option: --with-clang

brew options llvm also showed nothing.

Then I found another page that suggests the simple

brew install llvm

This worked for me. It is with homebrew 2.4.0, on MacOS Mojave.

If you need to have llvm first in your PATH run (replace <your_username> with your username):

echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> /Users/<your_username>/.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"
Share:
12,714

Related videos on Youtube

kaiser
Author by

kaiser

Updated on August 06, 2022

Comments

  • kaiser
    kaiser almost 2 years

    So I just installed Xcode on my Mac and now I would like to install LLVM as well in order to play around a bit with LLVM itself. Currently the compiler can (obviously) not find the required header files. So what is the best way to install LLVM if you already have clang, packed with Xcode, on your system?

    Thanks in advance.

  • akst
    akst almost 9 years
    Could you explain the arguments you used to install install llvm via homebrew?
  • Hongxu Chen
    Hongxu Chen almost 9 years
    @ABot It's very intuitive and you can use brew options llvm for details.
  • junjiah
    junjiah over 8 years
    A typo here: export LD_LIBRARY_PATH:/usr/local/Cellar/llvm/HEAD/lib:$LD_LIBRARY_‌​PATH the first colon should be =
  • auspicious99
    auspicious99 almost 4 years
    brew install --with-clang --with-lld --with-python --HEAD llvm doesn't work now (in June 2020) on my Macbook Pro with MacOS Mojave and Homebrew 2.4.0. brew options llvm also doesn't show anything.
  • Hongxu Chen
    Hongxu Chen almost 4 years
    usually you should use brew info llvm to check available options first :)