編譯帶有除錯資訊的 LLVM/Clang
1 2 3 4 5 6 |
$ git clone https://github.com/llvm/llvm-project.git $ cd llvm–project $ mkdir build $ cd build $ cmake –G Ninja –DCMAKE_BUILD_TYPE=Debug –DLLVM_ENABLE_PROJECTS=‘clang’ –DLLVM_ENABLE_RTTI=ON –DLLVM_CCACHE_BUILD=ON –DLLVM_BUILD_LLVM_DYLIB=ON –DLLVM_LINK_LLVM_DYLIB=ON –DLLVM_ENABLE_ABI_BREAKING_CHECKS=OFF –DLLVM_USE_LINKER=lld –DLLVM_USE_SPLIT_DWARF=ON –DLLVM_TARGETS_TO_BUILD=‘X86’ –DLLVM_INCLUDE_EXAMPLES=OFF –DLLVM_INCLUDE_BENCHMARKS=OFF –DLLVM_INCLUDE_TESTS=OFF –DLLVM_ENABLE_LTO=OFF –DLLVM_OPTIMIZED_TABLEGEN=ON –DCLANG_ENABLE_STATIC_ANALYZER=OFF –DCLANG_ENABLE_ARCMT=OFF ../llvm $ ninja –j |
- LLVM CMake Build Reference: https://llvm.org/docs/CMake.html
- LLVM Getting Started: https://llvm.org/docs/GettingStarted.html
快速編譯以及快速連結請參考 LLVM Getting Started 的 Common Problem 的 CMake 選項,上面的範例 CMake 選項已經將 Common Problem 的選項開啟 (或關閉)。
替換編譯時使用的 dynamic library
CMake – CMakeLists.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 |
cmake_minimum_required(VERSION 3.18) project(parser) add_executable(parser parser.cpp) target_include_directories(parser PUBLIC /home/louie/arrc/llvm–project/build/include) set_target_properties(parser PROPERTIES CXX_STANDARD 14) find_library(CLANG_LIB NAMES clang–cpp HINTS /home/louie/arrc/llvm–project/build/lib) find_library(debugLLVM_LIB NAMES LLVM–10 HINTS /home/louie/arrc/llvm–project/build/lib NO_DEFAULT_PATH) target_link_libraries(parser ${CLANG_LIB} ${debugLLVM_LIB}) |
Makefile
1 |
–Wl,–rpath,{YOUR_PATH_TO_LLVM_PROJECT}/llvm–project/build/lib {YOUR_PATH_TO_LLVM_PROJECT}/llvm–project/build/lib/libclang–cpp.so |
編譯連結時出現 undefined reference to `llvm::DisableABIBreakingChecks’
- 確認 include directories 是不是正確的:
target_include_directories( foobar PUBLIC /home/llvm-project/build/include)
- 確認編譯 LLVM/Clang 時是否有加上
LLVM_ENABLE_ABI_BREAKING_CHECKS=OFF
- 可以透過
cmake .
來更新 build options
- 可以透過
- make clean 後重新編譯
Leave a Reply