[cfe-dev] How to add custom include dir to the header search path?

Robert Ankeney rrankene at gmail.com
Tue Apr 9 10:43:39 PDT 2013


Something like:
HeaderSearchOptions &headerSearchOptions =
theCompInst->getHeaderSearchOpts();
headerSearchOptions.AddPath("D:/test/include", clang::frontend::Angled,
false, false, false);

should do it.


>
> I'm writing a tools (do some static check) using clang lib . This is my
> code:
>
> void main()
> {
>     DiagnosticOptions diagnosticOptions;
>     TextDiagnosticPrinter *printer = new
> TextDiagnosticPrinter(llvm::nulls(),
>         diagnosticOptions);
>     llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagIDs;
>     DiagnosticsEngine diagnostics(diagIDs, printer);
>     LangOptions langOpts;
>
>     TargetOptions targetOpts;
>     targetOpts.Triple = llvm::sys::getDefaultTargetTriple();
>     TargetInfo *pti = TargetInfo::CreateTargetInfo(diagnostics,
> targetOpts);
>     FileSystemOptions fsopts;
>     FileManager fileManager(fsopts);
>     SourceManager sourceManager(diagnostics, fileManager);
>
>     HeaderSearch headerSearch(fileManager, diagnostics, langOpts, pti);
>
>     CompilerInstance *theCompInst = new CompilerInstance();
>     theCompInst->setDiagnostics(&diagnostics);
>     Preprocessor *pp = new Preprocessor(diagnostics, langOpts,
> pti,sourceManager, headerSearch, *theCompInst);
>
>     const FileEntry *pFile = fileManager.getFile(file_name);
>     sourceManager.createMainFileID(pFile);
>
>
> theCompInst->getDiagnosticClient().BeginSourceFile(theCompInst->getLangOpts(),pp);
>     theCompInst->setPreprocessor(pp);
>     theCompInst->setSourceManager(&sourceManager);
>     theCompInst->setTarget(pti);
>     theCompInst->setDiagnostics(&diagnostics);
>     SourceManager &sourceMgr = theCompInst->getSourceManager();
>     theCompInst->createASTContext();
>     Rewriter rewriter;
>     rewriter.setSourceMgr(sourceMgr,langOpts);
>
>
>     MyASTConsumer consumer(rewriter);
>     ParseAST(theCompInst->getPreprocessor(), &consumer,
> theCompInst->getASTContext());
>     theCompInst->getDiagnosticClient().EndSourceFile();
> }
>
> I want to check some C/C++ code using this tools. But *.h file and *.c file
> is not in the same filefold.
>
> Example:
>   test.c context:
>     #include "test.h"
>      .........
>
> test.c in D:\test\test.c
> test.h in D:\test\include\test.h
>
> So I need to add "D:\test\include" to the header search path. How to do
> that
> in my code?
> Thanks all!
>
>
>
> --
> View this message in context:
> http://clang-developers.42468.n3.nabble.com/How-to-add-custom-include-dir-to-the-header-search-path-tp4031389.html
> Sent from the Clang Developers mailing list archive at Nabble.com.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130409/305870d9/attachment.html>


More information about the cfe-dev mailing list