title: How to load a dynamically library via PhysFS?
body: <p>Here's my predicament: I am using <a href="https://icculus.org/physfs/" rel="nofollow noreferrer">PhysFS</a>, which allows me to treat multiple directories and archives as one virtual directory. This is for a video game in the future, which I intend to make modder-friendly. PhysFS is the best way to make it modding-friendly.</p>
  
  <p>At the same time, I also intend to use a script-extender of a sort that dnyamically loads libraries and registers them in Lua. <a href="https://github.com/Metalhead33/LuaModulaLoader" rel="nofollow noreferrer">I already created a crude, makeshift, largerly proof-of-concept Lua script extender</a>.</p>
  
  <p>So what is my issue? My issue is that <em>dlopen / LoadLibrary</em> only works with files on a real filesystem. And I want to load via PhysFS. I load the file via PHYSFS_openRead, then use PHYSFS_read to load the file's full content into a memory buffer.</p>
  
  <p>Some people suggested loading the <em>.so / .dll</em> file into the memory from PhysFS, and then writing it out to /tmp in Linux, or C:\temp in Windows, and then dlopen-ing it. <strong>But I don't think that's a very elegant way to do it.</strong></p>
  
  <p>So... any other ideas? I did look into <a href="https://en.wikipedia.org/wiki/Mmap" rel="nofollow noreferrer">mmap</a> and thought maybe I could manually load the ELF file <em>(on Linux)</em> and somehow manually extract the functions, and finally register them for Lua, but so far, <a href="https://bitbucket.org/metalhead33foundation/elfload/src" rel="nofollow noreferrer">all I could produce was a program that gave me information about the elf</a>.</p>
  
  <p>People said that I should look into <a href="https://www.gnu.org/software/libjit/" rel="nofollow noreferrer">LibJIT</a>, but I'm not exactly sure how that would help me.</p>
  
  <p>So what should I do? How do I load a library into memory via PhysFS, and use an <strong>alternative to dlopen</strong> to... dlsym the functions out of it?</p>
  
  <p><em>Please don't suggest dlopen, unless you genuinely suggest that I write out the file temporarily.</em></p>
  
  <p><strong>My question is largerly: how do I link? How do I get the functions out of the library which I already have in memory? And why do some people suggest <a href="https://www.gnu.org/software/libjit/" rel="nofollow noreferrer">LibJIT</a> to me?</strong></p>