How to build clang/examples/PrintFunctionNames?

前端 未结 4 1011
失恋的感觉
失恋的感觉 2021-02-08 00:33

I need some simple example to start using clang. I downloaded llvm and clang and built:

mkdir llvm-build
cd llvm-build
../llvm/configure
make

I

相关标签:
4条回答
  • 2021-02-08 01:04

    Most assuredly you will have your LLVM trunk checkout and under the tools path you have checked out Clang trunk as well [explained under building Clang via http://clang.llvm.org/get_started.html.

    Makefile Build Guide: http://llvm.org/docs/MakefileGuide.html

    On OS X the build set up is a bit different, but on Debian Linux I'm building it daily as follows:

    ../trunk/configure --enable-target=x86_64,arm,cpp,cbe --with-built-clang --enable-pic --enable-polly --enable-shared --with-cxx-include-arch=x86_64 --enable-optimized --with-optimize-option=-Os --enable-assertions --disable-bootstrap --disable-multilib --enable-jit --enable-threads --no-create --no-recursion

    then applying the make -j (n+1 number of cores) on the command for my Pentium D 945 system:

    make [building against autotools make -j (n+1) doesn't always building llvm cleanly as it does against cmake. So if you want to run all cores, expect the possibility of running make -j(n+1) more than once to result in a clean build.

    Standard form without accessing multiple cores:

    make BUILD_EXAMPLES='1' //Read the note below

    always results in a clean build, and if it doesn't report a bug to LLVM.

    Note: If you're at the top level you can svn update the llvm trunk, project-test trunk and clang trunk as follows:

    make trunk

    Then go and run make again now that BUILD_EXAMPLES=1 is configured ahead of time.

    make BUILD_EXAMPLES='1'

    NOTE: Autotools will allow one to configure the BUILD_EXAMPLES='1' but will ignore the flag when you go to run make if you don't explicitly include BUILD_EXAMPLES='1' after make on the command line.

    At the top of the LLVM tree you build against running make BUILD_EXAMPLES='1' will build the LLVM specific examples, then going inside your build/tools/clang path you then must run make BUILD_EXAMPLES='1' again to build the Clang examples.

    Hence:

    LLVM Top:

    make BUILD_EXAMPLES='1' // for LLVM examples cd tools/clang make BUILD_EXAMPLES='1' // for Clang specific examples

    Verify the examples installing under /usr/local/bin for LLVM and /usr/local/lib/ for Clang.

    If you use CMAKE the default location for the binary examples is under /usr/local/examples

    0 讨论(0)
  • 2021-02-08 01:06

    Go into llvm-build/tools/clang, and run "make BUILD_EXAMPLES=1".

    0 讨论(0)
  • 2021-02-08 01:06

    I followed the instructions at http://clang.llvm.org/get_started.html with two exceptions:

    1. My build dir is inside the source dir (i.e. cd llvm ; mkdir build), but I don't think it's relevant.
    2. I issued cmake as so :

      cd build

      cmake -DLLVM_BUILD_EXAMPLES=1 -DCLANG_BUILD_EXAMPLES=1 ..

    After that (and compiling of course (make -j8)) I could find the examples in the build dir :

    find -iname '*printfunctionname*'
    ./lib/PrintFunctionNames.so
    ...
    
    0 讨论(0)
  • 2021-02-08 01:13

    I tried to do something similar yesterday: get a list of methods in a class using clang and succeeded. Maybe my post helps here also. My best help was this AST Matchers tutorial.

    0 讨论(0)
提交回复
热议问题