I'm developing a clang based tool with which I process the AST generated by clang. Right now I'm developing inside the llvm-project tree (I cloned the whole repository) as mentioned in this tutorial. I've created the CMakeLists.txt as mentioned and I executed the cmake command as seen in the tutorial.
The project compiles and the output binary file is located in the build/bin with the other binaries inside the llvm-project source tree. When I execute my binary from the build/bin, upon parsing the input c++ file, everything goes well.
But, when I copy the generated binary to my home directory or anywhere else and I execute it, upon the parsing, it does not manage to find the standard headers for instance stddef.h:
/usr/include/stdlib.h:32:10: fatal error: 'stddef.h' file not found
My question is why it can find the header in one place and not in another? In one of the forum I found this: Some header files (stddef.h, stdarg.h, and others) are shipped with Clang — these are called builtin includes. Clang searches for them in a directory relative to the location of the clang binary.
I've checked the build directory, in which the binary is located originally, and it contains lib/clang/include directory in which there is also the file stddef.h. Is it possible that by executing in place the binary, it founds this path and when I copy it somewhere else it does not find the right path?
EDIT:
The command I execute is:
build/bin/mytool source.cpp -- -I(list of headers without system headers)