0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Mac OS安装LLVM

Last updated at Posted at 2019-07-05

简介

mac OS系统并没有LLVM工具,但是安装Xcode之后能调用基本的LLVM编译命令如clang,而如果想要调用llc等命令的话只能下载并安装完整的LLVM工具。

编译环境

  • OS: mac OS 10.14.3

另外还需要CMake工具,可以使用brew install cmake进行安装

安装步骤

  1. 获取LLVM源代码,放置在~/llvm/
> cd ~
> svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
  1. 获取Clang源代码,放置在~/llvm/tools/clang/
> cd ~/llvm/tools
> svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
  1. (Optional)获取extra Clang tools代码,源代码放置在~/llvm/tools/clang/tools/
> cd ~/llvm/tools/clang/tools
> svn co http://llvm.org/svn/llvm-project/clang-tools-extra/trunk extra
  1. (Optional)获取Compiler-RT代码,源代码放置在~/llvm/projects/
> cd ~/llvm/projects
> svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
  1. (Optional, wasm used)获取lld代码,源代码放置在~/llvm/tools/
> cd ~/llvm/tools
> svn co http://llvm.org/svn/llvm-project/lld/trunk lld
  1. 建立build目录并且在该目录下进行编译,注意LLVM禁止源码内编译(in-tree build is not supported)
> cd ~/llvm
> mkdir build
> cd build
> cmake -G "Unix Makefiles" \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
  -DLLVM_BUILD_LLVM_DYLIB=ON \
  --enable-optimized \
  --enable-targets=host-only \
  ../../llvm
> make
  • -G = 指定生成编译器
  • -DCMAKE_BUILD_TYPE = 调试版本(Debug)或者发布版本(Release)
  • -DCMAKE_EXPORT_COMPILE_COMMANDS = 是否输出编译命令
  • -DLLVM_BUILD_LLVM_DYLIB = 是否添加libLLVM共享库

更多的编译项可以参考LLVM的编译文档CMake的官方文档

配置环境变量

~/.bash_profile中添加~/llvm/build/bin,然后运行一下,就可以愉快地玩耍了。

.bash_profile
export PATH=${PATH}:~/llvm/build/bin
> source ~/.bash_profile

参考

Getting Started: Building and Running Clang
LLVM for Grad Students

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?