<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I want to create LLVM passes on OS X Yosemite. First, I built LLVM as such (based on <a href="http://llvm.org/docs/GettingStarted.html" class="">http://llvm.org/docs/GettingStarted.html</a> and trial & error):<div class=""><br class=""></div><div class="">...<br class=""><div class=""><div class="">$ mkdir build && cd build</div><div class="">$ CC=clang CXX="clang++ -stdlib=libc++" ../llvm/configure --enable-libcpp --enable-shared</div><div class="">$ make</div><div class="">$ make install</div></div></div><div class=""><br class=""></div><div class="">Then, I tested it with the following command. It worked!</div><div class=""><br class=""></div><div class="">$ opt -load /usr/local/lib/LLVMHello.dylib -hello <test.bc>/dev/null</div><div class=""><br class=""></div><div class="">However, when attempting to build my own pass in OS X Yosemite, I ran into confusing linking problems:</div><div class=""><br class=""></div><div class="">$ c++ $(CXXFLAGS) SourceLineAnnotator.cpp -c -o SourceLineAnnotator.o</div><div class="">$ c++ SourceLineAnnotator.o -shared -o annotate.so</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">Undefined symbols for architecture x86_64:</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  "llvm::ModulePass::assignPassManager(llvm::PMStack&, llvm::PassManagerType)", referenced from:</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">      vtable for cs380c::SourceLineAnnotator in SourceLineAnnotator.o</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  "llvm::ModulePass::~ModulePass()", referenced from:</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">      cs380c::SourceLineAnnotator::~SourceLineAnnotator() in SourceLineAnnotator.o</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  "llvm::raw_ostream::write(char const*, unsigned long)", referenced from:</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">      llvm::raw_ostream::operator<<(llvm::StringRef) in SourceLineAnnotator.o</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  "llvm::raw_ostream::operator<<(unsigned long)", referenced from:</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">      llvm::raw_ostream::operator<<(unsigned int) in SourceLineAnnotator.o</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  "llvm::PassRegistry::registerPass(llvm::PassInfo const&, bool)", referenced from:</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">      llvm::RegisterPass<cs380c::SourceLineAnnotator>::RegisterPass(char const*, char const*, bool, bool) in SourceLineAnnotator.o</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  "llvm::PassRegistry::getPassRegistry()", referenced from:</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">      llvm::RegisterPass<cs380c::SourceLineAnnotator>::RegisterPass(char const*, char const*, bool, bool) in SourceLineAnnotator.o</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  "llvm::AssemblyAnnotationWriter::~AssemblyAnnotationWriter()", referenced from:</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">      SourceLineAssemblyAnnotationWriter::~SourceLineAssemblyAnnotationWriter() in SourceLineAnnotator.o</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  "llvm::Pass::releaseMemory()", referenced from:</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">      vtable for cs380c::SourceLineAnnotator in SourceLineAnnotator.o</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  "llvm::Pass::dumpPassStructure(unsigned int)", referenced from:</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">      vtable for cs380c::SourceLineAnnotator in SourceLineAnnotator.o</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  "llvm::Pass::getAsImmutablePass()", referenced from:</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">      vtable for cs380c::SourceLineAnnotator in SourceLineAnnotator.o</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  "llvm::Pass::getAsPMDataManager()", referenced from:</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">      vtable for cs380c::SourceLineAnnotator in SourceLineAnnotator.o</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  "llvm::Pass::preparePassManager(llvm::PMStack&)", referenced from:</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">      vtable for cs380c::SourceLineAnnotator in SourceLineAnnotator.o</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  "llvm::Pass::getAdjustedAnalysisPointer(void const*)", referenced from:</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">      vtable for cs380c::SourceLineAnnotator in SourceLineAnnotator.o</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  "llvm::outs()", referenced from:</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">      cs380c::SourceLineAnnotator::runOnModule(llvm::Module&) in SourceLineAnnotator.o</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  "llvm::ModulePass::createPrinterPass(llvm::raw_ostream&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const", referenced from:</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">      vtable for cs380c::SourceLineAnnotator in SourceLineAnnotator.o</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  "llvm::ModulePass::getPotentialPassManagerType() const", referenced from:</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">      vtable for cs380c::SourceLineAnnotator in SourceLineAnnotator.o</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  "llvm::Instruction::getMetadataImpl(llvm::StringRef) const", referenced from:</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">      llvm::Instruction::getMetadata(llvm::StringRef) const in SourceLineAnnotator.o</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  "llvm::Pass::getPassName() const", referenced from:</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">      vtable for cs380c::SourceLineAnnotator in SourceLineAnnotator.o</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  "llvm::Pass::verifyAnalysis() const", referenced from:</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">      vtable for cs380c::SourceLineAnnotator in SourceLineAnnotator.o</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  "llvm::Pass::print(llvm::raw_ostream&, llvm::Module const*) const", referenced from:</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">      vtable for cs380c::SourceLineAnnotator in SourceLineAnnotator.o</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  "llvm::Module::print(llvm::raw_ostream&, llvm::AssemblyAnnotationWriter*) const", referenced from:</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">      cs380c::SourceLineAnnotator::runOnModule(llvm::Module&) in SourceLineAnnotator.o</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  "vtable for llvm::ModulePass", referenced from:</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">      llvm::ModulePass::ModulePass(char&) in SourceLineAnnotator.o</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  "vtable for llvm::AssemblyAnnotationWriter", referenced from:</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">      llvm::AssemblyAnnotationWriter::AssemblyAnnotationWriter() in SourceLineAnnotator.o</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  "vtable for llvm::Pass", referenced from:</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">      llvm::Pass::Pass(llvm::PassKind, char&) in SourceLineAnnotator.o</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">ld: symbol(s) not found for architecture x86_64</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">clang: error: linker command failed with exit code 1 (use -v to see invocation)</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">make: *** [annotate.so] Error 1</div></div><div class=""><br class=""></div><div class="">Eventually, I discovered the .so file could be successfully compiled as follows:</div><div class=""><br class=""></div><div class="">$ c++ SourceLineAnnotator.o -shared `/usr/local/bin/llvm-config --ldflags --libs --system-libs` -o annotate.so</div><div class=""><br class=""></div><div class="">By adding the flags specified, I can now compile the pass to a .so file. However, when I attempt to load it with opt, I get another type of error (also related to linking from what I can tell):</div><div class=""><br class=""></div><div class="">$ opt -load annotate.so -annotate <test.bc>/dev/null</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">opt: CommandLine Error: Option 'print-before-all' registered more than once!</div><div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);" class="">LLVM ERROR: inconsistency in registered CommandLine options</div></div><div class=""><br class=""></div><div class="">I’m quite stuck. I have fought with linker errors for weeks now and I’m not sure what to try. Any help would be greatly appreciated.</div><div class=""><br class=""></div><div class="">Andrew Selvia</div></body></html>