本文部份内容引用:
中文维基百科。
结构化编译器前端--clang介绍。前端
clang是LLVM编译器工具集的一个用于编译C、C++、Objective-C的前端。LLVM项目的目标是提供一个GNU编译器套装(gcc)的替代品,由苹果公司的赞助开发,其源代码受权采用的是类BSD的伊利诺伊大学厄巴纳-香槟分校开源码许可。python
相比于gcc,clang具备以下优势:git
当前 Clang 还处在不断完善过程当中,相比于gcc, clang在如下方面还须要增强:github
纯Windows环境:
能够从http://llvm.org/releases/下载相应的安装包进行安装。目前最新版本为3.8。
shell
apt-cyg install clang
sudo yum install clang
sudo apt-get install clang-3.4 clang-3.4-doc libclang-common-3.4-dev libclang-3.4-devlibclang1-3.4 libclang1-3.4-dbg libllvm-3.4-ocaml-dev libllvm3.4 libllvm3.4-dbg lldb-3.4 llvm-3.4 llvm-3.4-dev llvm-3.4-doc llvm-3.4-examples llvm-3.4-runtime clang-modernize-3.4 clang-format-3.4 python-clang-3.4 lldb-3.4-dev
git clone git@github.com:llvm-mirror/llvm.git
cd llvm/tools git clone git@github.com:llvm-mirror/clang.git
cd ../projects git clone git@github.com:llvm-mirror/compiler-rt.git
cd ../.. mkdir build cd build ../llvm/configure --enable-optimized --enable-assertions make make install
clang的用法与gcc基本相同,咱们能够写一个脚原本验证一下编译器是否已经安装完成:模块化
import os import sys import shutil if not len(sys.argv) in range(2, 3): print("Usage: hello_c.py <compiler>") exit(1) code = "#include <stdio.h>\n int main(void) { printf(\"hello world!\\n\"); return 0;} " if(not os.path.exists("example")): os.mkdir("example") file = open(r"example/hello.c",'w') file.writelines(code) file.close() cmd = sys.argv[1] + r" example/hello.c -o example/test.exe" os.system(cmd) os.system(r"example/test.exe") if(os.path.exists("example")): shutil.rmtree("example")
而后,咱们只须要在shell中输入python hello_c.py clang
便可,若是看到输出一行“hello world”说明编译器已经能够正常工做。
tornado