1 //===- lib/Linker/LinkLibraries.cpp - Link LLVM libraries -----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Reid Spencer and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains routines to handle finding libraries and linking them in.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Linker.h"
15 #include "llvm/Module.h"
19 /// LinkInLibrary - links one library into the HeadModule
21 Linker::LinkInLibrary(const std::string& Lib)
23 // Determine where this library lives.
24 sys::Path Pathname = FindLib(Lib);
25 if (Pathname.isEmpty())
26 return warning("Cannot find library '" + Lib + "'");
28 // If its an archive, try to link it in
29 if (Pathname.isArchive()) {
30 if (LinkInArchive(Pathname)) {
31 return error("Cannot link archive '" + Pathname.toString() + "'");
34 return warning("Supposed library '" + Lib + "' isn't a library.");
39 /// LinkLibraries - takes the specified library files and links them into the
40 /// main bytecode object file.
43 /// Libraries - The list of libraries to link into the module.
50 Linker::LinkInLibraries(const std::vector<std::string> &Libraries) {
52 // Process the set of libraries we've been provided
53 for (unsigned i = 0; i < Libraries.size(); ++i) {
54 if (LinkInLibrary(Libraries[i]))
58 // At this point we have processed all the libraries provided to us. Since
59 // we have an aggregated module at this point, the dependent libraries in
60 // that module should also be aggregated with duplicates eliminated. This is
61 // now the time to process the dependent libraries to resolve any remaining
63 const Module::LibraryListType& DepLibs = Composite->getLibraries();
64 for (Module::LibraryListType::const_iterator I = DepLibs.begin(),
65 E = DepLibs.end(); I != E; ++I) {
66 if (LinkInLibrary(*I))