[cfe-dev] Compilation error on commented-out code

DbdM Tbt spin.x2k at gmail.com
Sat Apr 26 07:42:59 PDT 2014


Hello and good day.

I have encountered an interesting compilation error that appears/disappears
depending on the existence of a statement.

[Background]
I am still exploring around clang and currently trying the following guide:
http://clang.llvm.org/docs/RAVFrontendAction.html
At first I was having a hard time reconciling the compilation process as my
thought process was:
1. is cmake needed since CmakeLists.txt? isn't this usually for win builds?
2. oh well, why not try using cmake? (note: I don't have prior experience
with cmake)
after a few hours ..
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.
4. no choice, ill just try to copy directly the Makefile of other tools.
(ignoring the CMakeLists for now)
After some time, compilation was ok and was now exploring around on how to
work with source codes being passed.
This exploration covered around CommonOptionsParser and ClangTool.
I added some source code, and for reference, the main() now looks like this:
----------------
int main(int argc, const char **argv) {
  llvm::sys::PrintStackTraceOnErrorSignal();
  clang::tooling::CommonOptionsParser OptionsParser(argc, argv);
  clang::tooling::ClangTool Tool(OptionsParser.getCompilations(),
                                 OptionsParser.getSourcePathList());
  std::vector<std::string> srcpaths = OptionsParser.getSourcePathList();
  std::vector<std::string>::iterator it = srcpaths.begin();
  for( it = srcpaths.begin(); it != srcpaths.end(); it++) {
    llvm::outs() << *it << "\n";
  }

  if (argc > 1) {
    clang::tooling::runToolOnCode(new FindNamedClassAction, argv[1]);
  }
}
-----------------
[Background:END]

Now the above code will compile nicely:
llvm[0]: Compiling FindClassDecls.cpp for Release+Asserts build
llvm[0]: Linking Release+Asserts executable my-tool (without symbols)
llvm[0]: ======= Finished Linking Release+Asserts Executable my-tool
(without symbols)

But if I comment-out the following line:
----------------
int main(int argc, const char **argv) {
...
  //if (argc > 1) {
  //  clang::tooling::runToolOnCode(new FindNamedClassAction, argv[1]);
  //}
...
----------------

I now get the following errors.
----------------
/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> > > >&)':
CompilationDatabase.cpp:(.text+0x1bda): undefined reference to
`clang::driver::Driver::Driver(llvm::StringRef, llvm::StringRef,
llvm::StringRef, clang::DiagnosticsEngine&)'
CompilationDatabase.cpp:(.text+0x1cec): undefined reference to
`clang::driver::Driver::BuildCompilation(llvm::ArrayRef<char const*>)'
CompilationDatabase.cpp:(.text+0x1dfc): undefined reference to
`clang::driver::Compilation::~Compilation()'
CompilationDatabase.cpp:(.text+0x1e10): undefined reference to
`clang::driver::Driver::~Driver()'
/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&)':
Tooling.cpp:(.text+0x15e): undefined reference to
`clang::CompilerInvocationBase::CompilerInvocationBase()'
Tooling.cpp:(.text+0x537): undefined reference to
`clang::CompilerInvocation::CreateFromArgs(clang::CompilerInvocation&, char
const* const*, char const* const*, clang::DiagnosticsEngine&)'
/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*)':
Tooling.cpp:(.text+0xa50): undefined reference to
`clang::CompilerInstance::CompilerInstance()'
Tooling.cpp:(.text+0xa5b): undefined reference to
`clang::CompilerInstance::setInvocation(clang::CompilerInvocation*)'
Tooling.cpp:(.text+0xa66): undefined reference to
`clang::CompilerInstance::setFileManager(clang::FileManager*)'
Tooling.cpp:(.text+0xa80): undefined reference to
`clang::CompilerInstance::createDiagnostics(clang::DiagnosticConsumer*,
bool)'
Tooling.cpp:(.text+0xa9d): undefined reference to
`clang::CompilerInstance::createSourceManager(clang::FileManager&)'
Tooling.cpp:(.text+0xaad): undefined reference to
`clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)'
Tooling.cpp:(.text+0xacc): undefined reference to
`clang::CompilerInstance::~CompilerInstance()'
/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*)':
Tooling.cpp:(.text+0xbe6): undefined reference to
`clang::CompilerInstance::createDiagnostics(clang::DiagnosticOptions*,
clang::DiagnosticConsumer*, bool, clang::CodeGenOptions const*)'
Tooling.cpp:(.text+0xc12): undefined reference to
`clang::ASTUnit::LoadFromCompilerInvocation(clang::CompilerInvocation*,
llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine>, bool, bool, bool,
clang::TranslationUnitKind, bool, bool, bool)'
/home/user/WORKSPACE/UNIFIED_LLVM/llvm-3.4/Release+Asserts/lib/libclangTooling.a(Tooling.o):
In function `clang::tooling::ToolInvocation::run()':
Tooling.cpp:(.text+0x3a9e): undefined reference to
`clang::TextDiagnosticPrinter::TextDiagnosticPrinter(llvm::raw_ostream&,
clang::DiagnosticOptions*, bool)'
Tooling.cpp:(.text+0x3c07): undefined reference to
`clang::driver::Driver::Driver(llvm::StringRef, llvm::StringRef,
llvm::StringRef, clang::DiagnosticsEngine&)'
Tooling.cpp:(.text+0x3cb4): undefined reference to
`clang::driver::Driver::BuildCompilation(llvm::ArrayRef<char const*>)'
Tooling.cpp:(.text+0x3e1b): undefined reference to
`clang::driver::Compilation::~Compilation()'
Tooling.cpp:(.text+0x3e2b): undefined reference to
`clang::driver::Driver::~Driver()'
Tooling.cpp:(.text+0x3e47): undefined reference to
`clang::TextDiagnosticPrinter::~TextDiagnosticPrinter()'
----------------
Furthermore, deleting the commented-out code also has same compile behavior.

Anyone have any insights as to what is happening here?

Thank you very much.

Sincerely,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140426/91c1e1a5/attachment.html>


More information about the cfe-dev mailing list