Can't compile clang

I'm getting this error trying to compile clang. Any ideas?

llvm[1]: Linking Release executable clang (without symbols)
Undefined symbols:
  "llvm::Serializer::EmitInt(unsigned int)", referenced from:
      llvm::SerializeTrait<clang::IdentifierInfo>::Emit(llvm::Serializer&,
clang::IdentifierInfo const&)in libclangBasic.a(IdentifierTable.o)
      llvm::SerializeTrait<clang::IdentifierInfo>::Emit(llvm::Serializer&,
clang::IdentifierInfo const&)in libclangBasic.a(IdentifierTable.o)
      llvm::SerializeTrait<clang::IdentifierInfo>::Emit(llvm::Serializer&,
clang::IdentifierInfo const&)in libclangBasic.a(IdentifierTable.o)
      llvm::SerializeTrait<clang::IdentifierInfo>::Emit(llvm::Serializer&,
clang::IdentifierInfo const&)in libclangBasic.a(IdentifierTable.o)
      llvm::SerializeTrait<clang::IdentifierInfo>::Emit(llvm::Serializer&,
clang::IdentifierInfo const&)in libclangBasic.a(IdentifierTable.o)
      llvm::SerializeTrait<clang::IdentifierInfo>::Emit(llvm::Serializer&,
clang::IdentifierInfo const&)in libclangBasic.a(IdentifierTable.o)
      llvm::SerializeTrait<clang::IdentifierInfo>::Emit(llvm::Serializer&,
clang::IdentifierInfo const&)in libclangBasic.a(IdentifierTable.o)
      llvm::SerializeTrait<clang::IdentifierInfo>::Emit(llvm::Serializer&,
clang::IdentifierInfo const&)in libclangBasic.a(IdentifierTable.o)
      llvm::SerializeTrait<clang::IdentifierInfo>::Emit(llvm::Serializer&,
clang::IdentifierInfo const&)in libclangBasic.a(IdentifierTable.o)
  "llvm::Deserializer::ReadCStr(std::vector<char, std::allocator<char>

&, bool)", referenced from:

      llvm::SerializeTrait<clang::IdentifierTable>::Read(llvm::Deserializer&,
clang::IdentifierTable&)in libclangBasic.a(IdentifierTable.o)
  "llvm::Deserializer::~Deserializer()", referenced from:
      (anonymous
namespace)::SerializationTest::ReadTable(llvm::sys::Path&)
                      in SerializationTest.o
  "llvm::Serializer::EmitRecord()", referenced from:
      (anonymous
namespace)::SerializationTest::WriteTable(llvm::sys::Path&,
clang::IdentifierTable*) in
SerializationTest.o
  "llvm::Deserializer::ReadInt()", referenced from:
      llvm::SerializeTrait<clang::IdentifierInfo>::Read(llvm::Deserializer&,
clang::IdentifierInfo&)in libclangBasic.a(IdentifierTable.o)
      llvm::SerializeTrait<clang::IdentifierInfo>::Read(llvm::Deserializer&,
clang::IdentifierInfo&)in libclangBasic.a(IdentifierTable.o)
      llvm::SerializeTrait<clang::IdentifierInfo>::Read(llvm::Deserializer&,
clang::IdentifierInfo&)in libclangBasic.a(IdentifierTable.o)
      llvm::SerializeTrait<clang::IdentifierInfo>::Read(llvm::Deserializer&,
clang::IdentifierInfo&)in libclangBasic.a(IdentifierTable.o)
      llvm::SerializeTrait<clang::IdentifierInfo>::Read(llvm::Deserializer&,
clang::IdentifierInfo&)in libclangBasic.a(IdentifierTable.o)
      llvm::SerializeTrait<clang::IdentifierInfo>::Read(llvm::Deserializer&,
clang::IdentifierInfo&)in libclangBasic.a(IdentifierTable.o)
      llvm::SerializeTrait<clang::IdentifierInfo>::Read(llvm::Deserializer&,
clang::IdentifierInfo&)in libclangBasic.a(IdentifierTable.o)
      llvm::SerializeTrait<clang::IdentifierInfo>::Read(llvm::Deserializer&,
clang::IdentifierInfo&)in libclangBasic.a(IdentifierTable.o)
      llvm::SerializeTrait<clang::IdentifierInfo>::Read(llvm::Deserializer&,
clang::IdentifierInfo&)in libclangBasic.a(IdentifierTable.o)
      llvm::SerializeTrait<clang::IdentifierTable>::Read(llvm::Deserializer&,
clang::IdentifierTable&)in libclangBasic.a(IdentifierTable.o)
  "llvm::Deserializer::Deserializer(llvm::BitstreamReader&)", referenced from:
      (anonymous
namespace)::SerializationTest::ReadTable(llvm::sys::Path&)
                      in SerializationTest.o
  "llvm::SerializeTrait<unsigned int>::Emit(llvm::Serializer&,
unsigned int)", referenced from:
      llvm::SerializeTrait<clang::IdentifierTable>::Emit(llvm::Serializer&,
clang::IdentifierTable const&)in libclangBasic.a(IdentifierTable.o)
  "llvm::Serializer::EmitCStr(char const*)", referenced from:
      llvm::SerializeTrait<clang::IdentifierTable>::Emit(llvm::Serializer&,
clang::IdentifierTable const&)in libclangBasic.a(IdentifierTable.o)
  "llvm::Serializer::~Serializer()", referenced from:
      (anonymous
namespace)::SerializationTest::WriteTable(llvm::sys::Path&,
clang::IdentifierTable*) in
SerializationTest.o
  "llvm::MemoryBuffer::getMemBufferCopy(char const*, char const*, char
const*)", referenced from:
      clang::Preprocessor::EnterMainSourceFile(unsigned int)in
libclangLex.a(Preprocessor.o)
  "llvm::cl::ParseCommandLineOptions(int, char**, char const*)",
referenced from:
      _main in clang.o
  "llvm::Serializer::Serializer(llvm::BitstreamWriter&, unsigned
int)", referenced from:
      (anonymous
namespace)::SerializationTest::WriteTable(llvm::sys::Path&,
clang::IdentifierTable*) in
SerializationTest.o
  "llvm::APInt::APInt(unsigned int, unsigned int, unsigned long long
const*)", referenced from:
      clang::Expr::isIntegerConstantExpr(llvm::APSInt&,
clang::ASTContext&, clang::SourceLocation*, bool) constin
libclangAST.a(Expr.o)
      clang::Sema::ActOnNumericConstant(clang::Token const&)in
libclangSEMA.a(SemaExpr.o)
      clang::Sema::ActOnNumericConstant(clang::Token const&)in
libclangSEMA.a(SemaExpr.o)
      clang::Sema::ActOnNumericConstant(clang::Token const&)in
libclangSEMA.a(SemaExpr.o)
      llvm::APInt::isIntN(unsigned int) constin libclangSEMA.a(SemaExpr.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status

Hi Chris,

The undefined symbols are functions defined in the mainline LLVM subversion repository (and not yet part of an actual release of LLVM). They are actually part of the libraries LLVMBitWriter.a and LLVMBitReader.a, and were added to those libraries within the last week or so.

I'm not certain what version of LLVM you are using, but please try updating to the latest (SVN version) of LLVM, rebuilding the core LLVM libraries, and see if the problem remains when building clang. It is odd that you are only getting linker errors; if you didn't have the supporting header files you wouldn't be able to compile anything (so I imagine you are already using a fairly recent version of LLVM).

Ted

Hi Ted,

Yeah, I had an old checkout of the normal llvm tree from svn (from a few weeks ago) in there, but the clang compile instructions didn't actually say that I needed to run 'make' in the llvm tree... so I didn't.

I did 'make libs-only' and then re-tried 'make' in the tools/clang dir, and that worked great! Having fun playing with it now. :slight_smile:

Thanks!

-Chris

Hi Chris,

Thanks for the feedback.

I have updated the build instructions with (hopefully) a few extra clarifying steps. I also added a disclaimer that clang really does require the LLVM support libraries, so if one encounters problems building clang they should first check if they have the latest version of LLVM.

Ted