[cfe-dev] Clang Tools

Manuel Klimek klimek at google.com
Mon Jan 21 01:14:36 PST 2013


On Mon, Jan 21, 2013 at 8:55 AM, Mohammad Adil <madil90 at gmail.com> wrote:

> I am in the process of writing a rewriter program. In fact, it is almost
> complete and it uses the clang internal api to process and rewriter a file
> (I create an ast and use astconsumer and visitor to parse it).
> Unfortunately, I am unable to find all c++ standard library paths
> effectively. Some one in this mailing list suggested that I should convert
> this to a clang tool. By "building separately from clang", I mean that I
> should be able to keep my tool separate from clang and build and use it
> separately from clang. The .json file method requires that my tool be
> present in the clang directory and built along with clang. Is there any
> other method to build stand-alone tools that compile just like any other
> clang program.
>

I'll re-ask the question: why do you need to build your tool separately
from clang?

Let me explain why I ask:
Any tool that uses clang's internal AST interfaces (as opposed to libclang)
is tightly coupled to a clang version anyway. As you noticed, there are for
example builtin headers to detect (note that those are different from the
standard library; builtin headers are definitions that are compiler
specific and will change in lock-step with the compiler code).

So, since a clang-AST-based tool will always be tightly coupled to a
specific version of clang (unless you use libclang), I do not see what the
reason would be to develop it separately from clang. If all you want is to
be able to build the tool independently of clang, that's already possible,
although probably a bit fiddly. You'll need a "make install" equivalent
tree of the clang/llvm build to a directory $prefix, then you set the
include search path to $prefix/include/clang and add a library path to
$prefix/lib, where you'll find all the static libraries of clang's AST -
you can add them so your build picks them up as static libraries, and you
should be ready to go. Note that you'll still need to fabricate an
installation of your tool where the clang driver is able to locate the
builtin headers of the clang you built against - the easiest way to achieve
that is to put your binary into $prefix/bin.

Cheers,
/Manuel

On Mon, Jan 21, 2013 at 12:37 PM, Manuel Klimek <klimek at google.com> wrote:
>
>> On Mon, Jan 21, 2013 at 8:31 AM, madil90 <madil90 at gmail.com> wrote:
>>
>>> Hi,
>>>    I had a standalone clang program which I am trying to convert to a
>>> clang
>>> tool. My basic requirement is that my tool should be able to find all
>>> default c++ paths and that it's build should be kept separate from the
>>> clang
>>> source. How can I do this? I tried using the .json file approach but that
>>> does not enable to build my tool separately from clang. Please guide me
>>> on
>>> how to write an independent tool (just give the steps. I will figure the
>>> rest out) that can easily find all c++ header files.
>>>
>>
>> Hi Adil,
>>
>> I'm not sure what you're looking for - that is, I don't understand what
>> your exact requirements are, and why the .json compilation database didn't
>> work for you. What exactly do you mean with "build separately from clang".
>> And why's that a requirement?
>>
>> Cheers,
>> /Manuel
>>
>>
>>>
>>> Regards,
>>> Adil
>>>
>>>
>>>
>>> --
>>> View this message in context:
>>> http://clang-developers.42468.n3.nabble.com/Clang-Tools-tp4029913.html
>>> Sent from the Clang Developers mailing list archive at Nabble.com.
>>> _______________________________________________
>>> cfe-dev mailing list
>>> cfe-dev at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>>
>>
>>
>
>
> --
> Mohammad Adil
> LUMS SSE
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130121/3ee8cfa1/attachment.html>


More information about the cfe-dev mailing list