Graham Wakefield
2008-Dec-18 22:19 UTC
[LLVMdev] Troubles with clang and llvm libraries and simple Xcode project
Hi, I'm having a hard time linking the LLVM/clang libraries in Xcode. I've been fighting this for a couple of days now, and decided to make a fresh checkout and a super-simple demo project to try and isolate the problem, but even so I'm getting undefined symbol errors in the linker for the static libraries LLVM is producing. This is really baffling, so probably I'm missing something super-basic, but here's what I did: svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm ... Checked out revision 61210. cd llvm cd tools svn co http://llvm.org/svn/llvm-project/cfe/trunk clang ... Checked out revision 61210. edit Makefile ... modified to add clang to the list of PARALLEL_DIRS ... cd .. ... I'm configuring with PIC because I'll need to use clang/LLVM within a library that will be dynamically loaded: ./configure -enable-pic -enable-optimized ... everything fine except: checking whether llvm-gcc is sane... dyld: Library not loaded: /usr/ lib/libiconv.2.dylib Referenced from: /usr/local/bin/llvm-gcc Reason: Incompatible library version: llvm-gcc requires version 7.0.0 or later, but libiconv.2.dylib provides version 5.0.0 no make -k ... mostly fine, I guess these are harmless?: /code/llvm/lib/AsmParser/llvmAsmParser.y contains 6 shift/reduce conflicts and 136 reduce/reduce conflicts. .. llvm[2]: Compiling llvmAsmParser.cpp for Release build /usr/share/bison.simple: In function 'int llvmAsmparse()': /usr/share/bison.simple:614: warning: comparison between signed and unsigned integer expressions /usr/share/bison.simple:626: warning: comparison between signed and unsigned integer expressions ... llvm[4]: Compiling DeclSerialization.cpp for Release build DeclSerialization.cpp: In static member function 'static clang::FunctionDecl* clang::FunctionDecl::CreateImpl (llvm::Deserializer&, clang::ASTContext&)': DeclSerialization.cpp:521: warning: 'numParams' may be used uninitialized in this function .. llvm[2]: Linking Release Shared Library LTO.dylib *** Warning: Linking the shared library /code/llvm/Release/lib/ libLTO.la against the non-libtool *** objects /code/llvm/Release/lib/LLVMCppBackend.o /code/llvm/ Release/lib/LLVMMSIL.o /code/llvm/Release/lib/LLVMCBackend.o /code/ llvm/Release/lib/LLVMXCore.o /code/llvm/Release/lib/LLVMPIC16.o /code/ llvm/Release/lib/LLVMCellSPUCodeGen.o /code/llvm/Release/lib/ LLVMCellSPUAsmPrinter.o /code/llvm/Release/lib/LLVMMips.o /code/llvm/ Release/lib/LLVMARMAsmPrinter.o /code/llvm/Release/lib/ LLVMARMCodeGen.o /code/llvm/Release/lib/LLVMIA64.o /code/llvm/Release/ lib/LLVMAlphaCodeGen.o /code/llvm/Release/lib/LLVMAlphaAsmPrinter.o / code/llvm/Release/lib/LLVMPowerPCAsmPrinter.o /code/llvm/Release/lib/ LLVMPowerPCCodeGen.o /code/llvm/Release/lib/LLVMSparcCodeGen.o /code/ llvm/Release/lib/LLVMSparcAsmPrinter.o /code/llvm/Release/lib/ LLVMX86AsmPrinter.o /code/llvm/Release/lib/LLVMX86CodeGen.o is not portable! make install ... llvm[3]: Installing Release Shared Library /usr/local/lib/ libLLVMHello.dylib mklib: install: warning: remember to run `mklib --finish /code/llvm/ Release/lib' ... And that's it. Then I make a simple command-line tool in Xcode, linking to the libraries in /usr/local/lib. Here's what xcode emits: Building target “weirdbug_nolib” of project “llvmAV” with configuration “Release” Checking Dependencies CompileC build/llvmAV.build/Release/weirdbug_nolib.build/Objects- normal/i386/main_weird.o /code/luaAV/oct08/mergathon/llvmAV/ main_weird.cpp normal i386 c++ com.apple.compilers.gcc.4_0 cd /code/luaAV/oct08/mergathon/llvmAV /Developer/usr/bin/gcc-4.0 -x c++ -arch i386 -pipe -Wno- trigraphs -fpascal-strings -Os -fmessage-length=0 -fvisibility- inlines-hidden -mmacosx-version-min=10.4 -I/code/luaAV/oct08/ mergathon/llvmAV/build/llvmAV.build/Release/weirdbug_nolib.build/ weirdbug_nolib.hmap -Wmost -Wno-four-char-constants -Wno-unknown- pragmas -F/code/luaAV/oct08/mergathon/llvmAV/build/Release -I/code/ luaAV/oct08/mergathon/llvmAV/build/Release/include -I/usr/local/ include -I/code/luaAV/oct08/mergathon/llvmAV/build/llvmAV.build/ Release/weirdbug_nolib.build/DerivedSources -D__STDC_CONSTANT_MACROS - D__STDC_LIMIT_MACROS -isysroot /Developer/SDKs/MacOSX10.4u.sdk -c / code/luaAV/oct08/mergathon/llvmAV/main_weird.cpp -o /code/luaAV/oct08/ mergathon/llvmAV/build/llvmAV.build/Release/weirdbug_nolib.build/ Objects-normal/i386/main_weird.o Ld /code/luaAV/oct08/mergathon/llvmAV/build/Release/weirdbug_nolib normal i386 mkdir /code/luaAV/oct08/mergathon/llvmAV/build/Release cd /code/luaAV/oct08/mergathon/llvmAV /Developer/usr/bin/g++-4.0 -o /code/luaAV/oct08/mergathon/llvmAV/ build/Release/weirdbug_nolib -L/code/luaAV/oct08/mergathon/llvmAV/ build/Release -L/usr/local/lib -F/code/luaAV/oct08/mergathon/llvmAV/ build/Release -filelist /code/luaAV/oct08/mergathon/llvmAV/build/ llvmAV.build/Release/weirdbug_nolib.build/Objects-normal/i386/ weirdbug_nolib.LinkFileList -lclangAnalysis -lclangAST -lclangBasic - lclangCodeGen -lclangDriver -lclangLex -lclangParse -lclangRewrite - lclangSema -lLLVMAnalysis -lLLVMArchive -lLLVMAsmParser - lLLVMAsmPrinter -lLLVMBitReader -lLLVMBitWriter -lLLVMCodeGen - lLLVMCore -lLLVMDebugger -lLLVMInstrumentation -lLLVMipa -lLLVMipo - lLLVMLinker -lLLVMScalarOpts -lLLVMSelectionDAG -lLLVMSupport - lLLVMSystem -lLLVMTarget -lLLVMTransformUtils -arch i386 -Wl,-Y,1455 - mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk At this point, I get hundreds of undefined symbols from both clang and LLVM. Seems like the libraries are not built correctly, but I can't see anything wrong with the steps I took above. I've included a selection of the linker errors below. /Developer/usr/bin/../libexec/gcc/i686-apple-darwin8/4.0.1/ld: Undefined symbols: clang::ASTConsumer::InitializeTU(clang::TranslationUnit&) clang::ASTConsumer::~ASTConsumer() ... vtable for clang::DeclRefExpr vtable for clang::BinaryOperator ... typeinfo for llvm::AliasAnalysis llvm::ConstantFoldCall(llvm::Function*, llvm::Constant* const*, unsigned int) llvm::ConstantFoldInstruction(llvm::Instruction*, llvm::TargetData const*) llvm::ConstantFoldLoadThroughGEPConstantExpr(llvm::Constant*, llvm::ConstantExpr*) llvm::CallGraphLinkVar llvm::CallGraphSCCPass::assignPassManager(llvm::PMStack&, llvm::PassManagerType) vtable for llvm::CallGraphSCCPass ... and so on, then: ... /usr/local/lib/libclangCodeGen.a(ModuleBuilder.o) reference to undefined clang::ASTConsumer::InitializeTU(clang::TranslationUnit&) /usr/local/lib/libclangCodeGen.a(ModuleBuilder.o) reference to undefined clang::ASTConsumer::~ASTConsumer() ... /usr/local/lib/libclangCodeGen.a(CGObjC.o) reference to undefined vtable for clang::DeclRefExpr /usr/local/lib/libclangCodeGen.a(CGObjC.o) reference to undefined vtable for clang::BinaryOperator ... /usr/local/lib/libLLVMCodeGen.a(LiveIntervalAnalysis.o) reference to undefined typeinfo for llvm::AliasAnalysis /usr/local/lib/libLLVMipo.a(GlobalOpt.o) reference to undefined llvm::ConstantFoldCall(llvm::Function*, llvm::Constant* const*, unsigned int) /usr/local/lib/libLLVMipo.a(GlobalOpt.o) reference to undefined llvm::ConstantFoldInstruction(llvm::Instruction*, llvm::TargetData const*) /usr/local/lib/libLLVMipo.a(GlobalOpt.o) reference to undefined llvm::ConstantFoldLoadThroughGEPConstantExpr(llvm::Constant*, llvm::ConstantExpr*) /usr/local/lib/libLLVMipo.a(InlineSimple.o) reference to undefined llvm::CallGraphLinkVar /usr/local/lib/libLLVMipo.a(InlineSimple.o) reference to undefined llvm::CallGraphSCCPass::assignPassManager(llvm::PMStack&, llvm::PassManagerType) /usr/local/lib/libLLVMipo.a(InlineSimple.o) reference to undefined vtable for llvm::CallGraphSCCPass ... and so on. Thanks for any help or advice you can offer!
Reasonably Related Threads
- [LLVMdev] llvm-config --cxxflags does not give the result the configuration script wants?
- [LLVMdev] llvm-config --cxxflags does not give the result the configuration script wants?
- [LLVMdev] share between AST and IR?
- [LLVMdev] share between AST and IR?
- [LLVMdev] type-system-rewrite branch near landing