ubuntu14.04安装llvm/clang 9.0预编译版本

1 ubuntu14.04安装llvm/clang 9.0预编译版本

下载llvm/clang prebuild:
https://releases.llvm.org/download.html#9.0.0
https://download.csdn.net/download/wwchao2012/12391517

xz -d clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-14.04.tar.xz
tar cvf clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-14.04.tar

mv clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-14.04 llvm
sudo mv llvm /usr/local/llvm

vi /etc/profile

export LLVM_HOME=/usr/local/llvm/bin
export PATH=$LLVM_HOME:$PATH:/usr/local/llvm/lib:/usr/local/llvm/include

source /etc/profile

设置clang为默认编译器

SET (CMAKE_C_COMPILER             "/usr/local/llvm/bin/clang")
SET (CMAKE_CXX_COMPILER           "/usr/local/llvm/bin/clang++")
export CPLUS_INCLUDE_PATH=/usr/local/llvm/include
export LD_LIBRARY_PATH=/usr/local/llvm/lib
export CXXFLAGS=-stdlib=libc++

2 ClangBuildAnalyzer编译安装

下载ClangBuildAnalyzer:https://github.com/aras-p/ClangBuildAnalyzer

unzip ClangBuildAnalyzer-master.zip
cd ClangBuildAnalyzer-master/
mkdir build && cd build
export CC=/usr/local/llvm/bin/clang
export CXX=/usr/local/llvm/bin/clang++
cmake_minimum_required(VERSION 3.5.1)
project(ClangBuildAnalyzer)

# 新增
SET (CMAKE_C_COMPILER             "/usr/local/llvm/bin/clang") # 新增
SET (CMAKE_CXX_COMPILER           "/usr/local/llvm/bin/clang++") # 新增
make -j8
mv ClangBuildAnalyzer /usr/bin/

3 include-what-you-use

下载include-what-you-use-clang_9.0:https://github.com/include-what-you-use/include-what-you-use

mkdir iwyu
cd iwyu

unzip include-what-you-use-clang_9.0.zip
cd include-what-you-use-clang_9.0/
mv ./include-what-you-use-clang_9.0 ./include-what-you-use/
cd ../

修改include-what-you-use/CMakeLists.txt

cmake_minimum_required(VERSION 3.4.3)

# 新增
SET (CMAKE_C_COMPILER             "/usr/local/llvm/bin/clang") # 新增
SET (CMAKE_CXX_COMPILER           "/usr/local/llvm/bin/clang++") # 新增

if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
  message(STATUS "IWYU: out-of-tree configuration")
  set(IWYU_IN_TREE OFF)
else()
  message(STATUS "IWYU: in-tree configuration")
  set(IWYU_IN_TREE ON)
endif()

...

# 修改
# Synthesize a clang-resource-headers target for out-of-tree builds (in-tree
# already has it available by default)
if (NOT IWYU_IN_TREE)
  # Use only major.minor.patch for the resource directory structure; some
  # platforms include suffix in LLVM_VERSION.
  set(llvm_ver ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH})
  set(clang_headers_src ${CMAKE_PREFIX_PATH}/include) #修改路径
  set(clang_headers_dst ${CMAKE_BINARY_DIR}/include) #修改路径

  file(GLOB_RECURSE in_files RELATIVE ${clang_headers_src} ${clang_headers_src}/*)
...
mkdir build && cd build
cmake -G "Unix Makefiles" -DCMAKE_PREFIX_PATH=/usr/local/llvm/ ../include-what-you-use
make -j8
mv include-what-you-use /usr/bin/

4 参考链接

  1. ubuntu下cmake 使用clang
  2. clang问题记:libc++和libstdc++
  3. clang 找不到标准库头文件错误

你可能感兴趣的:(clang)