Paths to system header files

Sorry about the format of the previous message. I write it again here.

Sorry, Jacob, no idea on how to use your solution in my code. Manuel, nothing is written in your message I think…
My code is something like this:

static cl::OptionCategory MyToolCategory(“My tool options”);

int main(int argc, const char **argv) {
CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
ClangTool Tool(OptionsParser.getCompilations(),
OptionsParser.getSourcePathList());
return Tool.run(newFrontendActionFactory().get());
}

What I was doing by the moment is to process argv before creating the object OptionsParser and then include internal Clang headers, but I guess I can’t do that when using Json compilation database. Could you help me with that? Otherwise, is there a way to ship in the executable all the necessary headers so that the user does not require to have clang installed?

Thanks.

El día 26 feb 2016 14:03, Pedro Delgado Perez pedro.delgadoperez@mail.uca.es escribió:

I haven't used the C++ interface, only the C interface. But look at the original post in the thread I linked to [1]. There it seems like "mapVirtualFile" in clang::tooling::ClangTool is used to add a virtual header file. See also the last post by "Mikhail Ramalho". You need to add the path where the virtual file is located as an include path.

[1] http://clang-developers.42468.n3.nabble.com/Builtin-headers-td4049705.html

Hello Pedro,

I was able to embed the builtin headers using vritual files as follow.

Right now, I have two vectors to hold the filename and its content.

std::vectorstd::string clang_headers_name;
std::vectorstd::string clang_headers_content;

For some reason I couldn’t get working using one std::vector<std::pair<std::string, std::string> > (neither using a map), but I didn’t dig it further to understand why.

So, the two vectors are filled with the header’s name and content, attached is the method I use to embed them. It isn’t an ideal solution but it works. I created a small script that (more or less) automatically converts all the builtin headers to strings. If you want it, just let me know.

After both vectors are filled, I simply do (bold):

clang::tooling::FixedCompilationDatabase Compilations(“./”, compiler_string);

std::vectorstd::string sources;
sources.push_back(“/esbmc_intrinsics.h”);
sources.push_back(path);

clang::tooling::ClangTool Tool(Compilations, sources);
Tool.mapVirtualFile(“/esbmc_intrinsics.h”, intrinsics);

for(auto it = clang_headers_name.begin(), it1 = clang_headers_content.begin();
(it != clang_headers_name.end()) && (it1 != clang_headers_content.end());
++it, ++it1)
Tool.mapVirtualFile(*it, *it1);

Tool.buildASTs(ASTs);

clang_headers.cpp (58.5 KB)