<div dir="ltr">Hello and good day.<br><br>I have encountered an interesting compilation error that appears/disappears depending on the existence of a statement.<br><br>[Background]<br>I am still exploring around clang and currently trying the following guide:<br>
<a href="http://clang.llvm.org/docs/RAVFrontendAction.html">http://clang.llvm.org/docs/RAVFrontendAction.html</a><br>At first I was having a hard time reconciling the compilation process as my thought process was:<br>1. is cmake needed since CmakeLists.txt? isn't this usually for win builds?<br>
2. oh well, why not try using cmake? (note: I don't have prior experience with cmake)<br>after a few hours ..<br>3. hmmm, the cmake operation created some directories and compiling took a long time and the find-class-decls executable was nowhere to be found.<br>
4. no choice, ill just try to copy directly the Makefile of other tools. (ignoring the CMakeLists for now)<br>After some time, compilation was ok and was now exploring around on how to work with source codes being passed.<br>
This exploration covered around CommonOptionsParser and ClangTool.<br>I added some source code, and for reference, the main() now looks like this:<br>----------------<br>int main(int argc, const char **argv) {<br>  llvm::sys::PrintStackTraceOnErrorSignal();<br>
  clang::tooling::CommonOptionsParser OptionsParser(argc, argv);<br>  clang::tooling::ClangTool Tool(OptionsParser.getCompilations(),<br>                                 OptionsParser.getSourcePathList());<br>  std::vector<std::string> srcpaths = OptionsParser.getSourcePathList();<br>
  std::vector<std::string>::iterator it = srcpaths.begin();<br>  for( it = srcpaths.begin(); it != srcpaths.end(); it++) {<br>    llvm::outs() << *it << "\n";<br>  }<br><br>  if (argc > 1) {<br>
    clang::tooling::runToolOnCode(new FindNamedClassAction, argv[1]);<br>  }<br>}<br>-----------------<br>[Background:END]<br><br>Now the above code will compile nicely:<br>llvm[0]: Compiling FindClassDecls.cpp for Release+Asserts build<br>
llvm[0]: Linking Release+Asserts executable my-tool (without symbols)<br>llvm[0]: ======= Finished Linking Release+Asserts Executable my-tool (without symbols)<br><br>But if I comment-out the following line:<br>----------------<br>
int main(int argc, const char **argv) {<br>...<br>  //if (argc > 1) {<br>  //  clang::tooling::runToolOnCode(new FindNamedClassAction, argv[1]);<br>  //}<br>...<br>----------------<br><br>I now get the following errors.<br>
----------------<br>/home/user/WORKSPACE/UNIFIED_LLVM/llvm-3.4/Release+Asserts/lib/libclangTooling.a(CompilationDatabase.o): In function `clang::tooling::stripPositionalArgs(std::vector<char const*, std::allocator<char const*> >, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&)':<br>
CompilationDatabase.cpp:(.text+0x1bda): undefined reference to `clang::driver::Driver::Driver(llvm::StringRef, llvm::StringRef, llvm::StringRef, clang::DiagnosticsEngine&)'<br>CompilationDatabase.cpp:(.text+0x1cec): undefined reference to `clang::driver::Driver::BuildCompilation(llvm::ArrayRef<char const*>)'<br>
CompilationDatabase.cpp:(.text+0x1dfc): undefined reference to `clang::driver::Compilation::~Compilation()'<br>CompilationDatabase.cpp:(.text+0x1e10): undefined reference to `clang::driver::Driver::~Driver()'<br>/home/user/WORKSPACE/UNIFIED_LLVM/llvm-3.4/Release+Asserts/lib/libclangTooling.a(Tooling.o): In function `clang::tooling::newInvocation(clang::DiagnosticsEngine*, llvm::SmallVector<char const*, 16u> const&)':<br>
Tooling.cpp:(.text+0x15e): undefined reference to `clang::CompilerInvocationBase::CompilerInvocationBase()'<br>Tooling.cpp:(.text+0x537): undefined reference to `clang::CompilerInvocation::CreateFromArgs(clang::CompilerInvocation&, char const* const*, char const* const*, clang::DiagnosticsEngine&)'<br>
/home/user/WORKSPACE/UNIFIED_LLVM/llvm-3.4/Release+Asserts/lib/libclangTooling.a(Tooling.o): In function `clang::tooling::FrontendActionFactory::runInvocation(clang::CompilerInvocation*, clang::FileManager*, clang::DiagnosticConsumer*)':<br>
Tooling.cpp:(.text+0xa50): undefined reference to `clang::CompilerInstance::CompilerInstance()'<br>Tooling.cpp:(.text+0xa5b): undefined reference to `clang::CompilerInstance::setInvocation(clang::CompilerInvocation*)'<br>
Tooling.cpp:(.text+0xa66): undefined reference to `clang::CompilerInstance::setFileManager(clang::FileManager*)'<br>Tooling.cpp:(.text+0xa80): undefined reference to `clang::CompilerInstance::createDiagnostics(clang::DiagnosticConsumer*, bool)'<br>
Tooling.cpp:(.text+0xa9d): undefined reference to `clang::CompilerInstance::createSourceManager(clang::FileManager&)'<br>Tooling.cpp:(.text+0xaad): undefined reference to `clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)'<br>
Tooling.cpp:(.text+0xacc): undefined reference to `clang::CompilerInstance::~CompilerInstance()'<br>/home/user/WORKSPACE/UNIFIED_LLVM/llvm-3.4/Release+Asserts/lib/libclangTooling.a(Tooling.o): In function `clang::tooling::(anonymous namespace)::ASTBuilderAction::runInvocation(clang::CompilerInvocation*, clang::FileManager*, clang::DiagnosticConsumer*)':<br>
Tooling.cpp:(.text+0xbe6): undefined reference to `clang::CompilerInstance::createDiagnostics(clang::DiagnosticOptions*, clang::DiagnosticConsumer*, bool, clang::CodeGenOptions const*)'<br>Tooling.cpp:(.text+0xc12): undefined reference to `clang::ASTUnit::LoadFromCompilerInvocation(clang::CompilerInvocation*, llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine>, bool, bool, bool, clang::TranslationUnitKind, bool, bool, bool)'<br>
/home/user/WORKSPACE/UNIFIED_LLVM/llvm-3.4/Release+Asserts/lib/libclangTooling.a(Tooling.o): In function `clang::tooling::ToolInvocation::run()':<br>Tooling.cpp:(.text+0x3a9e): undefined reference to `clang::TextDiagnosticPrinter::TextDiagnosticPrinter(llvm::raw_ostream&, clang::DiagnosticOptions*, bool)'<br>
Tooling.cpp:(.text+0x3c07): undefined reference to `clang::driver::Driver::Driver(llvm::StringRef, llvm::StringRef, llvm::StringRef, clang::DiagnosticsEngine&)'<br>Tooling.cpp:(.text+0x3cb4): undefined reference to `clang::driver::Driver::BuildCompilation(llvm::ArrayRef<char const*>)'<br>
Tooling.cpp:(.text+0x3e1b): undefined reference to `clang::driver::Compilation::~Compilation()'<br>Tooling.cpp:(.text+0x3e2b): undefined reference to `clang::driver::Driver::~Driver()'<br>Tooling.cpp:(.text+0x3e47): undefined reference to `clang::TextDiagnosticPrinter::~TextDiagnosticPrinter()'<br>
----------------<br>Furthermore, deleting the commented-out code also has same compile behavior.<br><br>Anyone have any insights as to what is happening here?<br><br>Thank you very much.<br><br>Sincerely,<br>David<br><br>
</div>