| 108 | } |
| 109 | |
| 110 | bool DynamicLibrary::load(const std::string& library_path) |
| 111 | { |
| 112 | unload(); |
| 113 | |
| 114 | #ifdef _WIN32 |
| 115 | SetLastError(0); |
| 116 | handle_ = static_cast<void*>(LoadLibraryA(library_path.c_str())); |
| 117 | |
| 118 | if (!handle_) |
| 119 | { |
| 120 | last_error_ = getWindowsError(); |
| 121 | if (last_error_.empty()) |
| 122 | { |
| 123 | last_error_ = "Unknown LoadLibrary error"; |
| 124 | } |
| 125 | return false; |
| 126 | } |
| 127 | |
| 128 | // The DLL is linked with /NOENTRY (no CRT startup), so C++ static |
| 129 | // constructors (e.g. CUDA fatbin registration) haven't run yet. |
| 130 | runStaticInitializers(static_cast<HMODULE>(handle_)); |
| 131 | #else |
| 132 | dlerror(); |
| 133 | handle_ = dlopen(library_path.c_str(), RTLD_LAZY | RTLD_LOCAL); |
| 134 | |
| 135 | if (!handle_) |
| 136 | { |
| 137 | const char* error = dlerror(); |
| 138 | last_error_ = error ? error : "Unknown dlopen error"; |
| 139 | return false; |
| 140 | } |
| 141 | #endif |
| 142 | |
| 143 | last_error_.clear(); |
| 144 | return true; |
| 145 | } |
| 146 | |
| 147 | void* DynamicLibrary::getSymbol(const std::string& symbol_name) |
| 148 | { |