1 //===-- DynamicLibrary.cpp - Runtime link/load libraries --------*- C++ -*-===//
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 header file implements the operating system DynamicLibrary concept.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/System/DynamicLibrary.h"
15 #include "llvm/Config/dlfcn.h"
18 //===----------------------------------------------------------------------===//
19 //=== WARNING: Implementation here must contain only TRULY operating system
20 //=== independent code.
21 //===----------------------------------------------------------------------===//
31 DynamicLibrary::DynamicLibrary(const char*filename) : handle(0) {
33 throw std::string(lt_dlerror());
35 handle = lt_dlopen(filename);
38 handle = lt_dlopenext(filename);
41 throw std::string("Can't open dynamic library:") + filename;
44 DynamicLibrary::~DynamicLibrary() {
46 lt_dlclose((lt_dlhandle)handle);
51 void *DynamicLibrary::GetAddressOfSymbol(const char *symbolName) {
52 assert(handle != 0 && "Invalid DynamicLibrary handle");
53 return lt_dlsym((lt_dlhandle) handle,symbolName);
57 DynamicLibrary::DynamicLibrary(const char*filename) : handle(0) {
58 assert(!"Have ltdl.h but not libltdl.a!");
61 DynamicLibrary::~DynamicLibrary() {
62 assert(!"Have ltdl.h but not libltdl.a!");
65 void *DynamicLibrary::GetAddressOfSymbol(const char *symbolName) {
66 assert(!"Have ltdl.h but not libltdl.a!");
76 #include "platform/DynamicLibrary.cpp"