ccls: link error to LLVMSupport

CMakeFiles/ccls.dir/src/main.cc.o: In function `OptionValue':
/home/shc/code/repos/ccls/build/clang+llvm-6.0.0-x86_64-linux-gnu-ubuntu-16.04/include/llvm/Support/CommandLine.h:575: undefined reference to `vtable for llvm::cl::OptionValue<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >'
CMakeFiles/ccls.dir/src/main.cc.o: In function `opt<char [5], llvm::cl::desc>':
/home/shc/code/repos/ccls/build/clang+llvm-6.0.0-x86_64-linux-gnu-ubuntu-16.04/include/llvm/Support/CommandLine.h:1359: undefined reference to `vtable for llvm::cl::opt<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, false, llvm::cl::parser<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >'
CMakeFiles/ccls.dir/src/main.cc.o: In function `parser':
/home/shc/code/repos/ccls/build/clang+llvm-6.0.0-x86_64-linux-gnu-ubuntu-16.04/include/llvm/Support/CommandLine.h:1028: undefined reference to `vtable for llvm::cl::parser<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >'
CMakeFiles/ccls.dir/src/main.cc.o: In function `OptionValue':
/home/shc/code/repos/ccls/build/clang+llvm-6.0.0-x86_64-linux-gnu-ubuntu-16.04/include/llvm/Support/CommandLine.h:575: undefined reference to `vtable for llvm::cl::OptionValue<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >'
CMakeFiles/ccls.dir/src/main.cc.o: In function `opt<char [9], llvm::cl::desc, llvm::cl::value_desc>':
/home/shc/code/repos/ccls/build/clang+llvm-6.0.0-x86_64-linux-gnu-ubuntu-16.04/include/llvm/Support/CommandLine.h:1359: undefined reference to `vtable for llvm::cl::opt<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, false, llvm::cl::parser<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >'
CMakeFiles/ccls.dir/src/main.cc.o: In function `parser':
/home/shc/code/repos/ccls/build/clang+llvm-6.0.0-x86_64-linux-gnu-ubuntu-16.04/include/llvm/Support/CommandLine.h:1028: undefined reference to `vtable for llvm::cl::parser<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >'
CMakeFiles/ccls.dir/src/main.cc.o: In function `OptionValue':
/home/shc/code/repos/ccls/build/clang+llvm-6.0.0-x86_64-linux-gnu-ubuntu-16.04/include/llvm/Support/CommandLine.h:575: undefined reference to `vtable for llvm::cl::OptionValue<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >'
CMakeFiles/ccls.dir/src/main.cc.o: In function `opt<char [16], llvm::cl::desc, llvm::cl::value_desc>':
/home/shc/code/repos/ccls/build/clang+llvm-6.0.0-x86_64-linux-gnu-ubuntu-16.04/include/llvm/Support/CommandLine.h:1359: undefined reference to `vtable for llvm::cl::opt<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, false, llvm::cl::parser<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >'
CMakeFiles/ccls.dir/src/main.cc.o: In function `parser':
/home/shc/code/repos/ccls/build/clang+llvm-6.0.0-x86_64-linux-gnu-ubuntu-16.04/include/llvm/Support/CommandLine.h:1028: undefined reference to `vtable for llvm::cl::parser<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >'
/home/shc/code/repos/ccls/build/clang+llvm-6.0.0-x86_64-linux-gnu-ubuntu-16.04/include/llvm/Support/CommandLine.h:1028: undefined reference to `vtable for llvm::cl::parser<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >'
clang-6.0: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

Is the bundled LLVM not compiled with c++11?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (17 by maintainers)

Most upvoted comments

Yes, -stdlib is used in both compiling and linking.

https://github.com/llvm-mirror/clang/tree/master/lib/Driver/ToolChains/Gnu.cpp#L2438

void Generic_GCC::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
                                               ArgStringList &CC1Args) const {
  if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
      DriverArgs.hasArg(options::OPT_nostdincxx))
    return;

  switch (GetCXXStdlibType(DriverArgs)) {
  case ToolChain::CST_Libcxx:
    addLibCxxIncludePaths(DriverArgs, CC1Args);
    break;

  case ToolChain::CST_Libstdcxx:
    addLibStdCxxIncludePaths(DriverArgs, CC1Args);
    break;
  }
}

https://github.com/llvm-mirror/clang/tree/master/lib/Driver/ToolChain.cpp#L752

void ToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
                                    ArgStringList &CmdArgs) const {
  assert(!Args.hasArg(options::OPT_nostdlibxx) &&
         "should not have called this");
  CXXStdlibType Type = GetCXXStdlibType(Args);

  switch (Type) {
  case ToolChain::CST_Libcxx:
    CmdArgs.push_back("-lc++");
    break;

  case ToolChain::CST_Libstdcxx:
    CmdArgs.push_back("-lstdc++");
    break;
  }
}

Same issue. Maybe due to mixed use of stdc++ and stdlibc++.

@MaskRay @scturtle If you want to use libcxx only, both linker flag and compile option should be set in cmake:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -v")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi")

I asked this question days ago and this is the only solution I have ever found