linux下clang+llvm3.3安装(ubuntu)

来源:互联网 发布:宁波php招聘 编辑:程序博客网 时间:2024/05/18 00:01

最近要用clang api进行一些简单的查错处理(往高里说叫Runtime Verification),结果配置环境弄了好久......(linux基础知识很重要.....makefile要学好, gcc要学好, 至少编译的时候多用用-###  -v , 看看库函数到底从哪里找到的, 理解.a  .so等文件类型 , 软连接, 多用locate(注意updatedb), 不要各种版本装得乱七八糟, 路径, 改动bash...)

终于能够正常运行里的代码了 https://github.com/loarabia/Clang-tutorial 


刚开始没仔细看llvm getting started           http://llvm.org/docs/GettingStarted.html

只是照着网上不全的教程看,出了一大堆问题,官方文档虽然好但也不能照抄,否则会装10+G的内容(Debug版且没有优化,我装的时候容量耗光了,还得扩展(在VM上))


正式开始教程:


1.安装前请最好保证以下需求是满足的:

PackageVersionNotesGNU Make3.79, 3.79.1Makefile/build processorGCC>=4.7.0C/C++ compiler1python>=2.5Automated test suite2GNU M41.4Macro processor for configuration3GNU Autoconf2.60Configuration script builder3GNU Automake1.9.6aclocal macro generator3libtool1.5.22Shared library manager3zlib>=1.2.3.4Compression library4

gcc-4.8的安装可以参加llvm官网的教程,也可以参见 http://eli.thegreenplace.net/2014/01/16/building-gcc-4-8-from-source-on-ubunu-12-04/

zlib教程一搜就出来了http://myswirl.blog.163.com/blog/static/513186422007101410382259/

其它的基本都满足(ubuntu 12.04.4)(cat /etc/issue)

可以先  apt-get install build-essential  一下

查看各软件版本一般可以用  软件名-v

2.正式开始安装

要安装以下东西

llvm-3.3.src

cfe-3.3.src

clang-tools-extra-3.3.src

compiler-rt-3.3.src

libcxx-3.3.src

教程在这里:  

http://www.cnblogs.com/codemood/p/3142848.html

tips: 不过如果前面环境配置有些问题导致

../llvm-3.3.src/configure --enable-optimized --enable-targets=host-only  不能找到c preprocessor之类的问题,可以自己指定
CC=你的gcc-4.8的路径(在安装目录下的/bin/gcc) CXX=你的g++-4.8的路径 CPP=同理 ../llvm-3.3.src/configure --enable-optimized --enable-targets=host-only

3.尝试clang-tutorial

先看Readme 改动 makefile 和 compile_commands.json 

可以先不把Makefile里的sources弄少一点,编译报错后

把函数内容改成现在使用的(根据错误信息改,我记得要把sourceManager改为fileManager)

如果遇到


cannot find -lxxx  请移步这里 http://blog.sciencenet.cn/blog-676535-541444.html

以下是tutorial2的执行情况:

能够得到test.c的各个token

int 'int'identifier 'footype'semi ';'int 'int'identifier 'main'l_paren '('r_paren ')'l_brace '{'typedef 'typedef'unsigned 'unsigned'long 'long'identifier 'bartype'semi ';'identifier 'printf'l_paren '('string_literal '"Hello World\n"'r_paren ')'semi ';'return 'return'numeric_constant '0'semi ';'r_brace '}'eof ''

这是test.c的内容

//#include <stdio.h>// This code is licensed under the New BSD license.// See LICENSE.txt for more details.int i = 4;extern int j;typedef int footype;int main(){typedef unsigned long bartype;printf("Hello World\n");return 0;}
0 0