Minas Abrahamyan
2010-Jul-14 09:29 UTC
[LLVMdev] How to cope with 'undefined reference' errors taken the example of building VMkit x86_64 version
Hi all, I haven't found this trick anywhere (including llvm/docs/MakefileGuide.html) so it maybe useful. This occurs only in 64 bit version of linux, linker of 32 bit system understands everything correctly. Situation: While building, at link stage, a 64bit version of some executable, with several archive libraries, say, A.a, B.a, C.a build fails with some "undefined reference to symbol" errors, Error occurs in try to link-in some symbol defined in B, which is undefined symbol in A library. Linker somehow looks for that symbol only in A library, where it is undefined, U-symbol, in terms of nm(1). Solution is to add in USEDLIBS line name of B library immediately after name of A, for every such A for which linker gets so confused. *** Example for VMkit: USEDLIBS = J3.a Classpath.a J3Compiler.a Allocator.a \ Mvm.a MvmCompiler.a $(GCLIB).a CommonThread.a make output: <<< make[1]: Leaving directory `/home/mn/tests/VMkit/vmkit/lib' make[1]: Entering directory `/home/mn/tests/VMkit/vmkit/tools/vmjc' llvm[1]: Compiling vmjc.cpp for Debug build llvm[1]: Linking Debug executable vmjc /home/mn/tests/VMkit/vmkit/Debug/lib/libGCMmap2.a(gcinit.o): In function `mvm::Collector::initialise()': /home/mn/tests/VMkit/vmkit/lib/Mvm/GCMmap2/gcinit.cpp:22: undefined reference to `GCAllocator::operator new(unsigned long)' /home/mn/tests/VMkit/vmkit/lib/Mvm/GCMmap2/gcinit.cpp:22: undefined reference to `GCAllocator::GCAllocator()' /home/mn/tests/VMkit/vmkit/Debug/lib/libGCMmap2.a(gcinit.o): In function `mvm::Collector::destroy()': /home/mn/tests/VMkit/vmkit/lib/Mvm/GCMmap2/gcinit.cpp:42: undefined reference to `GCAllocator::~GCAllocator()' /home/mn/tests/VMkit/vmkit/lib/Mvm/GCMmap2/gcinit.cpp:42: undefined reference to `GCAllocator::operator delete(void*)' collect2: ld returned 1 exit status make[1]: *** [/home/mn/tests/VMkit/vmkit/Debug/bin/vmjc] Error 1 make[1]: Leaving directory `/home/mn/tests/VMkit/vmkit/tools/vmjc' make: *** [all] Error 1>>>Solution: change USEDLIBS to: USEDLIBS = J3.a Classpath.a J3.a J3Compiler.a Allocator.a \ Mvm.a MvmCompiler.a $(GCLIB).a Allocator.a CommonThread.a Here J3.a and Allocator.a were repeated. After change it builds OK. Regards, Minas Abrahamyan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100714/23b09ed9/attachment.html>