[cfe-dev] How can I add default header search paths to a RefactoringTool?
Péter Németh
hun.nemethpeter at gmail.com
Sun Sep 22 23:59:23 PDT 2013
Hi,
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:
clang version 3.4
(https://github.com/llvm-mirror/clang.git65da8e952da32730202356290bb889c8839bbef5)
(
http://llvm.org/git/llvm.git 189c6235e7d783928c94cbfe4bccb39e4bd0b84f)
Target: x86_64-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.7
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.7.3
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7.3
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7
*error: invalid argument '-std=c++11' not allowed with 'C/ObjC'*
clang Invocation:
...
clang -cc1 version 3.4 based upon LLVM 3.4svn default target
x86_64-unknown-linux-gnu
...
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
In file included from UserData.h:3:
In file included from
/usr/include/boost/date_time/posix_time/posix_time.hpp:14:
*/usr/include/boost/date_time/compiler_config.hpp:11:10: fatal error:
'cstdlib' file not found
#include <cstdlib>
^*
But when I use the clang++ I got no error, but the following output
#include <...> search starts here:
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/backward
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/x86_64-linux-gnu/c++/4.7
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
So the search path list is not initialized correctly in the tool. I have no
idea how to fix that.
In compile_commands.json I have this:
...
"command": "g++ -v -std=c++11 -Wall UserData.h -c"
...
I init RefactoringTool in this way:
cl::opt<std::string> build_path(cl::Positional, cl::desc("<build-path>"));
cl::list<std::string> source_paths(cl::Positional, cl::desc("<source0> [...
<sourceN>]"), cl::OneOrMore);
static void
InitCompilationDatabase(std::shared_ptr<CompilationDatabase>& compilations)
{
if (!compilations)
{
std::string error_message;
compilations.reset(CompilationDatabase::loadFromDirectory(build_path,
error_message));
if (!compilations)
llvm::report_fatal_error(error_message);
}
}
int main(int argc, const char **argv)
{
llvm::sys::PrintStackTraceOnErrorSignal();
std::shared_ptr<CompilationDatabase>
compilations(FixedCompilationDatabase::loadFromCommandLine(argc, argv));
cl::ParseCommandLineOptions(argc, argv);
InitCompilationDatabase(compilations);
tooling::RefactoringTool tool(*compilations, source_paths);
ast_matchers::MatchFinder finder;
...
std::unique_ptr<clang::tooling::FrontendActionFactory>
frontendAction(newFrontendActionFactory(&finder));
return tool.run(frontendAction.get());
}
Thanks,
Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130923/d964aa75/attachment.html>
More information about the cfe-dev
mailing list