<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/75014>75014</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Driver/Libtooling: Clang can’t seem to find C++ system include directories
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Sirraide
      </td>
    </tr>
</table>

<pre>
    
I can’t seem to figure out how to get Clang to add C++ system include directories to the include path. I’m not sure this really counts as an issue (I’ve also already tried asking in the `#libtooling` channel on the LLVM Discord server, and so far, we haven’t been able to find an answer to this).

Essentially, I want to take some C++ code that includes C++ stdlib headers (e.g. `#include <cstdlib>`), parse it, and then do something with the resulting `ASTContext`. I started out trying to run a frontend action on it via `runToolOnCode`, but that doesn’t seem to add any include directories.

Next, I tried using `clang::ASTUnit::LoadFromCompilerInvocation` to create an `ASTContext` from a `CompilerInvocation`, which I managed to obtain in one of three ways:
- Calling `clang::CompilerInvocation::CreateFromArgs`,
- Creating a `clang::driver::Driver`, using that to create a `Compilation`, extracting the arguments from that compilation, calling `AddClangCXXStdlibIncludeArgs` on the tool chain that that compilation gives me, presumably to add the include paths that I’m looking for, and finally passing all of those arguments to `clang::CompilerInvocation::CreateFromArgs`,
- Calling `clang::createInvocation`.

So far, while the latter two approaches do manage to pull in *some* system headers (e.g. it manages to find `stdlib.h`), it still can’t seem to find any C++ system headers (e.g. `<cstdlib>`).

It would be helpful to know what the ‘proper’ way of accomplishing any of this is; I can, of course, add the include paths manually as command-line arguments to any of the three approaches mentioned above, but doing so 1. becomes rather untenable once different platforms are involved, and 2. seems rather janky seeing as Clang *knows* what the right include directories are (after all, it never fails to find them when I try and run `clang foo.cc` from the terminal), and it seems like a bad idea to try and do that manually when *some* part of Clang already knows how to do that.

So, to summarise, all I would like to be able to do is take some C++ code as a string and get an `ASTContext` from it that I can work with, and I want clang to behave in pretty much exactly the same manner as though I had run it from the terminal.

Not sure how much this helps, but I’m running Fedora 39.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVk9z2z4O_TT0BVOPTMVpfPDBdZuZzHR3D-nu_K6QCElsKNJDQnb97XdASbaTuruX3yWxJBJ_Hh4egCnZ1hNt1fqLWn9d4MBdiNtXGyNaQ4sqmPNWFV9VsXuBGr36ptVToTYbhkTUAwdobDtEgjAwdOEkb1pi2Dv0rTygMbBX-ovSXyCdE1MP1tduMATGRqo5REtJTnJHl08H5G4JLxd3PfjAkMQRdzZBJHTuDHUYPCfABOjBpjQQKP10vXYkQJcCoIuE5gwcLRnA9GZ9C9Znl-qxULp0tuIQnPWteiyg7tB7chDGI9-__-cf8NWmOkQDieKRotJ7QG8gBWgwP50IOjzSLUQVkQesHI04eSNhok8nimPCNim9WY74jn-_pUSerWQnRl_ghJ7zYXwjSKGnC5p1MIIG8oxaugLNxtkKOkJDMQkmtGyXU6ozxqrc1-NBVX7Lnzbi8oAxEVieM-SOPJiQfXMnwJ0sdxmXSGlwLK_UY7F7_bEPnukXq8diCS-QGCOTyczgeLYjH-LgAaGJclQAqdkGL0BbhqNFsRQH_yME9y-_D4ZyYHuoxIjkagKlezQUnqE_3yPXO4D_KQFmZEcyDGmKvxbGqnKnyt3u9ce_veXx4XtA8xxDvw_9wTqKL_4YapSohSkcoI6ETFLajyhImj3knO7ezrTpbN3BC_TosSUjBkPFaL3wM3iC0AB3kQhOeE4SUk7jE-zRud9Dv-NnfJ-DlDx2sU2j74sl-Sam8IMxE61QPf_-Ov4egx5By_W4AeCa522C9IujVDlfIMDYDj1J12Zwso365pLeQ33NbGdMVpL9X3-9Zqq-jOWdkpgbVFpXmja3NPJvVqG1R0rQUya40LbHyp1n3nxUnjQauJUfF0IWjSZcWr-xPovQQURU0HNuLFZIt2ly-DtKdLfYI_DvKPWO669XceqsqFBH4JBZ5OcUAA-HGLDuKEl_jwSUcA-Dc8I-pXfS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