LLVM-3.5 —— 01记,编译 LLVM 3.5.0 clang and clang-query

本文详细介绍了如何从头开始,包括使用git克隆LLVM项目,修改源代码以添加公开方法,配置CMake和configure选项,以及编译、安装和测试Clang的过程。

包括编译:clang clang-tools-extra

0, prepare env


sudo apt install llvm
sudo apt install clang

使用最新的g++ 会出错。


1, source code

$ git clone --recursive
$ cd llvm-project

$ git checkout llvmorg-3.5.0
$ cp -r ./clang ./llvm/tools/
$ mkdir llvm/tools/clang/tools/extra
$ cp -r ./clang-tools-extra/* llvm/tools/clang/tools/extra/
$ ls llvm/tools/clang/tools/extra/


2,修改源代码

直接 cmake make后,会发现如下error:

于是增加了一个 public:

(base) hipper@hipper-G21:~/llvm_3_4_0_ex/browse/llvm-project$ git diff
diff --git a/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h b/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
index f9df3781257e..f64d66e4fb94 100644
--- a/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
+++ b/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h
@@ -134,6 +134,7 @@ public:
 //===----------------------------------------------------------------------===//
   template <typename T>
   class IntrusiveRefCntPtr {
+  public:
     T* Obj;

   public:

3,cmake 配置 llvm

3.1 用 cmake 配置 构建 llvm

$ cd llvm-project

$ mkdir build

$ mkdir ../local_d

$ cd build

$ cmake -G "Unix Makefiles"            \
-DCLANG_ENABLE_STATIC_ANALYZER=1     \
-DLLVM_ENABLE_ASSERTIONS=On          \
-DCMAKE_BUILD_TYPE=Debug             \
-DCMAKE_INSTALL_PREFIX=/home/hipper/llvm_3_4_0_ex/browse/local_d   \
-DLLVM_ENABLE_LIBCXX=1               \
-DLLVM_ENABLE_PROJECTS="all"         \
 ../llvm

3.2 使用configure 来配置构建llvm

跟上一篇记录的 llvmorg-3.4.0 的构建过程一样

./configure --prefix=/home/hipper/llvm_3_4_0_ex/browse/local_d

make -j

make install

4, 编译安装

make -j install

5,测试


clang-query

attendanceRtspNew.libvlc.main | debug | arm64-v8a Compiler exited with error code 1: D:\Sdk\ndk\21.1.6352462\toolchains\llvm\prebuilt\windows-x86_64\bin\clang.exe -xc --target=aarch64-none-linux-android24 --gcc-toolchain=D:/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=D:/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64/sysroot -DyylRecord_EXPORTS -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -O0 -fno-limit-debug-info -fPIC E:\ZK_code\baiduFace\8.0\attendanceRtspNew\libvlc\src\main\cpp\yyl_record.c -fpch-preprocess -v -dD -E Android (6317467 based on r365631c1) clang version 9.0.8 (https://android.googlesource.com/toolchain/llvm-project e0caee08e5f09b374a27a676d04978c81fcb1928) (based on LLVM 9.0.8svn) Target: aarch64-none-linux-android24 Thread model: posix InstalledDir: D:\Sdk\ndk\21.1.6352462\toolchains\llvm\prebuilt\windows-x86_64\bin Found candidate GCC installation: D:/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64/lib/gcc/aarch64-linux-android\4.9.x Selected GCC installation: D:/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64/lib/gcc/aarch64-linux-android/4.9.x Candidate multilib: .;@m64 Selected multilib: .;@m64 "D:\\Sdk\\ndk\\21.1.6352462\\toolchains\\llvm\\prebuilt\\windows-x86_64\\bin\\clang.exe" -cc1 -triple aarch64-none-linux-android24 -E -disable-free -disable-llvm-verifier -discard-value-names -main-file-name yyl_record.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu generic -target-feature +neon -target-abi aapcs -mllvm -aarch64-fix-cortex-a53-835769=1 -fallow-half-arguments-and-returns -dwarf-column-info -debug-info-kind=standalone -dwarf-version=4 -debugger-tuning=gdb -v -ffunction-sections -fdata-sections -resource-dir "D:\\Sdk\\ndk\\21.1.6352462\\toolchains\\llvm\\prebuilt\\windows-x86_64\\lib64\\clang\\9.0.8" -D yylRecord_EXPORTS -D ANDROID -D _FORTIFY_SOURCE=2 -D ___CIDR_DEFINITIONS_END -isysroot D:/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64/sysroot -internal-isystem D:/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/local/include -internal-isystem "D:\\Sdk\\ndk\\21.1.6352462\\toolchains\\llvm\\prebuilt\\windows-x86_64\\lib64\\clang\\9.0.8\\include" -internal-externc-isystem D:/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/aarch64-linux-android -internal-externc-isystem D:/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64/sysroot/include -internal-externc-isystem D:/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include -O0 -Wformat -fdebug-compilation-dir "E:\\ZK_code\\baiduFace\\8.0\\attendanceRtspNew\\libvlc\\.cxx\\cmake\\debug\\arm64-v8a" -ferror-limit 19 -fmessage-length 0 -stack-protector 2 -fno-signed-char -fobjc-runtime=gcc -fdiagnostics-show-option -dD -o - -x c "E:\\ZK_code\\baiduFace\\8.0\\attendanceRtspNew\\libvlc\\src\\main\\cpp\\yyl_record.c" clang -cc1 version 9.0.8 based upon LLVM 9.0.8svn default target x86_64-w64-windows-gnu ignoring nonexistent directory "D:/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64/sysroot/include" #include "..." search starts here: #include ...> search starts here: D:/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/local/include D:\Sdk\ndk\21.1.6352462\toolchains\llvm\prebuilt\windows-x86_64\lib64\clang\9.0.8\include D:/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/aarch64-linux-android D:/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include End of search list. E:\ZK_code\baiduFace\8.0\attendanceRtspNew\libvlc\src\main\cpp\yyl_record.c:7:10: fatal error: &#39;vlc_common.h&#39; file not found #include "vlc_common.h" ^~~~~~~~~~~~~~ 1 error generated. "D:\\Sdk\\ndk\\21.1.6352462\\toolchains\\llvm\\prebuilt\\windows-x86_64\\bin\\clang.exe" -cc1 -triple aarch64-none-linux-android24 -E -disable-free -disable-llvm-verifier -discard-value-names -main-file-name compiler-file4211565723826675682 -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu generic -target-feature +neon -target-abi aapcs -mllvm -aarch64-fix-cortex-a53-835769=1 -fallow-half-arguments-and-returns -dwarf-column-info -debug-info-kind=standalone -dwarf-version=4 -debugger-tuning=gdb -v -ffunction-sections -fdata-sections -resource-dir "D:\\Sdk\\ndk\\21.1.6352462\\toolchains\\llvm\\prebuilt\\windows-x86_64\\lib64\\clang\\9.0.8" -D yylRecord_EXPORTS -D ANDROID -D _FORTIFY_SOURCE=2 -D ___CIDR_DEFINITIONS_END -isysroot D:/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64/sysroot -internal-isystem D:/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/local/include -internal-isystem "D:\\Sdk\\ndk\\21.1.6352462\\toolchains\\llvm\\prebuilt\\windows-x86_64\\lib64\\clang\\9.0.8\\include" -internal-externc-isystem D:/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/aarch64-linux-android -internal-externc-isystem D:/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64/sysroot/include -internal-externc-isystem D:/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include -O0 -Wformat -fdebug-compilation-dir "E:\\ZK_code\\baiduFace\\8.0\\attendanceRtspNew\\libvlc\\.cxx\\cmake\\debug\\arm64-v8a" -ferror-limit 19 -fmessage-length 0 -stack-protector 2 -fno-signed-char -fobjc-runtime=gcc -fdiagnostics-show-option -dD -o - -x c "C:\\Users\\admin\\AppData\\Local\\Temp\\compiler-file4211565723826675682" clang -cc1 version 9.0.8 based upon LLVM 9.0.8svn default target x86_64-w64-windows-gnu ignoring nonexistent directory "D:/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64/sysroot/include" #include "..." search starts here: #include ...> search starts here: D:/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/local/include D:\Sdk\ndk\21.1.6352462\toolchains\llvm\prebuilt\windows-x86_64\lib64\clang\9.0.8\include D:/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/aarch64-linux-android D:/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include End of search list.
07-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值