First step towards LLVM clang plugin

  • Step 0 : Obtain Clang
  • Step 1 : Obtain ninja and build
  • Step 2 : Obtain cmake and build
  • Step 3 : Build clang
  • Step 4 : Clang tool
  • End
  • Ref
  • 吐槽

  • This article almost copy part of the official article, but fix many bugs that may impede newbees on the way to develop a clang plugin.

    Environment : macOS

    Step 0 : Obtain Clang

    mkdir ~/clang-llvm && cd ~/clang-llvm
    git clone
    cd llvm/tools
    git clone
    cd clang/tools
    git clone extra

    Step 1 : Obtain ninja and build

    cd ~/clang-llvm
    git clone
    cd ninja
    git checkout release
    sudo cp ninja /usr/local/bin/

    Step 2 : Obtain cmake and build

    Your default cmake may not contain ninja support, so build cmake ourself.

    cd ~/clang-llvm
    git clone
    cd cmake
    sudo make install

    Step 3 : Build clang

    cd ~/clang-llvm
    mkdir build && cd build
    cmake -G Ninja ../llvm -DLLVM_BUILD_TESTS=ON  # Enable tests; default is off.
    sudo ninja install

    Of course , you should run the unittests before ninja install, but normally I run the unittest , always encounters some not pass. But just ignore these ‘errors’.

    ninja check       # Test LLVM only.
    ninja clang-test  # Test Clang only.

    Step 4 : Clang tool

    Just goto Create a ClangTool


    will continue…


    • Introduction to the Clang AST (youtube video)

    All came from :