<div dir="ltr"><div><div><div>Hi,<br><br></div>I try to make a little tool for LibTooling based on clang-tools-extra/tool-template. My problem is that it does not initialize default C++ header search paths. So when I invoke my tool I got the following:<br>
<span style="font-family:courier new,monospace">clang version 3.4 (<a href="https://github.com/llvm-mirror/clang.git">https://github.com/llvm-mirror/clang.git</a> 65da8e952da32730202356290bb889c8839bbef5) (<a href="http://llvm.org/git/llvm.git">http://llvm.org/git/llvm.git</a> 189c6235e7d783928c94cbfe4bccb39e4bd0b84f)<br>
Target: x86_64-unknown-linux-gnu<br>Thread model: posix<br>Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.7<br>Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.7.3<br>Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7<br>
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7.3<br>Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7<br><b>error: invalid argument '-std=c++11' not allowed with 'C/ObjC'</b><br>
clang Invocation:</span><br>...<br><br>clang -cc1 version 3.4 based upon LLVM 3.4svn default target x86_64-unknown-linux-gnu<br><br>...<br><br><span style="font-family:courier new,monospace">#include "..." search starts here:<br>
#include <...> search starts here:<br> /usr/local/include<br> /usr/include/x86_64-linux-gnu<br> /usr/include<br></span></div><div><span style="font-family:courier new,monospace">End of search list.<br>In file included from UserData.h:3:<br>
In file included from /usr/include/boost/date_time/posix_time/posix_time.hpp:14:<br><b>/usr/include/boost/date_time/compiler_config.hpp:11:10: fatal error: 'cstdlib' file not found<br>#include <cstdlib><br> ^</b></span><br>
<br></div><div>But when I use the clang++ I got no error, but the following output<br><span style="font-family:courier new,monospace">#include <...> search starts here:<br> /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7<br>
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/backward<br> /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/x86_64-linux-gnu/c++/4.7<br> /usr/local/include<br> /usr/include/x86_64-linux-gnu<br> /usr/include<br>
End of search list.<br></span><br></div><div>So the search path list is not initialized correctly in the tool. I have no idea how to fix that.<br></div><div></div><div><br>In compile_commands.json I have this:<br>...<br>"command": "g++ -v -std=c++11 -Wall UserData.h -c"<br>
...<br></div><div><br></div>I init RefactoringTool in this way:<br><br><span style="font-family:courier new,monospace">cl::opt<std::string> build_path(cl::Positional, cl::desc("<build-path>"));<br>cl::list<std::string> source_paths(cl::Positional, cl::desc("<source0> [... <sourceN>]"), cl::OneOrMore);<br>
<br> static void<br>InitCompilationDatabase(std::shared_ptr<CompilationDatabase>& compilations)<br>{<br> if (!compilations)<br> {<br> std::string error_message;<br> compilations.reset(CompilationDatabase::loadFromDirectory(build_path, error_message));<br>
if (!compilations)<br> llvm::report_fatal_error(error_message);<br> }<br>}<br><br>int main(int argc, const char **argv)<br>{<br> llvm::sys::PrintStackTraceOnErrorSignal();<br><br> std::shared_ptr<CompilationDatabase> compilations(FixedCompilationDatabase::loadFromCommandLine(argc, argv));<br>
cl::ParseCommandLineOptions(argc, argv);<br><br> InitCompilationDatabase(compilations);<br><br> tooling::RefactoringTool tool(*compilations, source_paths);<br> ast_matchers::MatchFinder finder;<br><br> ...<br><br> std::unique_ptr<clang::tooling::FrontendActionFactory> frontendAction(newFrontendActionFactory(&finder));<br>
<br> return tool.run(frontendAction.get());<br>}<br></span><br><br></div>Thanks,<br>Peter<br><div><br></div></div>