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() + "'");
32 } else if (Pathname.isBytecodeFile()) {
34 if (LinkInFile(Pathname))
35 return error("Cannot link file '" + Pathname.toString() + "'");
37 } else if (Pathname.isDynamicLibrary()) {
38 return warning("Library '" + Lib + "' is a native dynamic library.");
40 return warning("Supposed library '" + Lib + "' isn't a library.");
45 /// LinkLibraries - takes the specified library files and links them into the
46 /// main bytecode object file.
49 /// Libraries - The list of libraries to link into the module.
56 Linker::LinkInLibraries(const std::vector<std::string> &Libraries) {
58 // Process the set of libraries we've been provided
59 for (unsigned i = 0; i < Libraries.size(); ++i) {
60 if (LinkInLibrary(Libraries[i]))
64 // At this point we have processed all the libraries provided to us. Since
65 // we have an aggregated module at this point, the dependent libraries in
66 // that module should also be aggregated with duplicates eliminated. This is
67 // now the time to process the dependent libraries to resolve any remaining
69 const Module::LibraryListType& DepLibs = Composite->getLibraries();
70 for (Module::LibraryListType::const_iterator I = DepLibs.begin(),
71 E = DepLibs.end(); I != E; ++I) {
72 if (LinkInLibrary(*I))