Returns library handle */
| 58 | |
| 59 | /** Returns library handle */ |
| 60 | static void* loadLibrary(std::string libraryPath) { |
| 61 | #if defined ARCH_WIN |
| 62 | SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS); |
| 63 | std::wstring libraryFilenameW = string::UTF8toUTF16(libraryPath); |
| 64 | HINSTANCE handle = LoadLibraryW(libraryFilenameW.c_str()); |
| 65 | SetErrorMode(0); |
| 66 | if (!handle) { |
| 67 | int error = GetLastError(); |
| 68 | throw Exception("Failed to load library %s: code %d", libraryPath.c_str(), error); |
| 69 | } |
| 70 | #else |
| 71 | // Since Rack 2, plugins on Linux/Mac link to the absolute path /tmp/Rack2/libRack.<ext> |
| 72 | // Create a symlink at /tmp/Rack2 to the system dir containting libRack. |
| 73 | std::string systemDir = system::getAbsolute(asset::systemDir); |
| 74 | std::string linkPath = "/tmp/Rack2"; |
| 75 | if (!settings::devMode) { |
| 76 | // Clean up old symbolic link in case a different edition was run earlier |
| 77 | system::remove(linkPath); |
| 78 | system::createSymbolicLink(systemDir, linkPath); |
| 79 | } |
| 80 | // Load library with dlopen |
| 81 | void* handle = NULL; |
| 82 | #if defined ARCH_LIN |
| 83 | handle = dlopen(libraryPath.c_str(), RTLD_NOW | RTLD_LOCAL); |
| 84 | #elif defined ARCH_MAC |
| 85 | handle = dlopen(libraryPath.c_str(), RTLD_NOW | RTLD_LOCAL); |
| 86 | #endif |
| 87 | if (!settings::devMode) { |
| 88 | system::remove(linkPath); |
| 89 | } |
| 90 | if (!handle) |
| 91 | throw Exception("Failed to load library %s: %s", libraryPath.c_str(), dlerror()); |
| 92 | #endif |
| 93 | return handle; |
| 94 | } |
| 95 | |
| 96 | typedef void (*InitCallback)(Plugin*); |
| 97 |
no test coverage detected