Question

Is there a way to load a dynamic library (so or dll) from a zip file, memory, or a custom pack file; or am I wasting my time? There is nothing I can find on the internet about it.

[EDIT] Clarification: I am looking for a runtime loading of the dynamic library using LoadLibraryEx (for Windows) or dlopen (for Linux). I can load the object from a directory with ease but I want to know if there is a way to put the shared/dynamic libraries in a ZIP file and load it from inside that file.

Was it helpful?

Solution

Yes. Note that loading libraries is platform-dependant (Windows uses the LoadLibrary(), dlopen call for example). On windows they are DLLs, and on *NIX, .SOs. It's not too difficult though, you can abstract away the actual implementation details to platform-specific classes which is just what many C++ plugin architectures do to allow the program to dynamically load a module at runtime.

As for the second part of your question, whilst I am not sure about the memory part, surely the .zip file part is simply a case of using an Api to extract said library from the zip file in to a temporary location and then dynamically loading the library from there? The same would be said for a custom-pack file, you just have a separation of concerns, namely:

  • Extracting the library from the custom-pack file, zip file, whatever to a temporary location (where the user has write permissions)
  • Loading the library as you normally would (e.g. LoadLibrary())
  • Clean up after yourself.

There is no (AFAIK) platform-agnostic, or even platform-dependent way of loading directly from a zip file, and nor should there be as it is somewhat niche. Extract elsewhere, load as business-as-usual.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top