so now I ne" /> so now I ne" /> so now I ne"/>

Get search paths for headers in the standard library in Clang?

33 Views Asked by At

I am building a programming language using C++, LLVM, Clang, LLDB, user can write import "@stdio.h" which is similar to #include <stdio.h> so now I need to support C like imports of headers, however I can't get the path to system headers, let alone parse them !

Other answers have gotten old, since llvm and clang API's have updated, I tried this code

void print_system_header_paths()  {
    clang::CompilerInstance CI;
    auto Invocation = std::make_shared<clang::CompilerInvocation>();
    CI.setInvocation(Invocation);
    // I can eliminate this line to get rid of an error but other answer suggested creating a preprocessor
    CI.createPreprocessor(clang::TranslationUnitKind::TU_Prefix);
    const clang::HeaderSearchOptions &HSOpts = CI.getInvocation().getHeaderSearchOpts();
    if (HSOpts.SystemHeaderPrefixes.empty()) {
        std::cout << "No system header paths found." << std::endl;
    } else {
        for (const auto &Path : HSOpts.SystemHeaderPrefixes) {
            std::cout << Path.Prefix << std::endl;
        }
    }
}

I also tried this command

clang -v -c -xc++ nul on windows however this requires parsing the command line output, I would prefer the C++ api

[Linked] How do I extract the search paths for headers in the standard library in Clang?

My programming language : https://github.com/Qinetik/chemical

0

There are 0 best solutions below