1

I created a lua module for windows, a DLL, which has a number of dependencies. These dependencies are required for the module DLL to function correctly, most of these dependencies are C++ runtime libraries (libstdc+-6.dll and libgcc_s_seh-1.dll among others). I am trying to load the module using the package.loadlib call:

init = assert(package.loadlib("C:\\Path\\To\\My\\Module.DLL", "luaopen_MyModule"))
init()

The dependencies and module DLL are located in another folder than the main executable's DLL. Because of this, it seems like package.loadlib cannot find the dependencies of the module. It works fine when the path to these dependencies is added to the PATH variable, but I am not allowed to modify PATH on the machines where the lua module will be used, neither can I link to the dependencies statically.

Is there any way to specify a search path for the dependencies from lua? The lua will only be used on Windows systems, so the solution may be platform dependent.

mkrufky
  • 3,268
  • 2
  • 17
  • 37
Shadowwolf
  • 973
  • 5
  • 13
  • You could require that those dll's are bundled along and moved with your dll? You could also try to statically link `libstdc++-6.dll` into your dll, so that an external dll is not needed. Mingw has an option for this, don't remember how it's called... – Chris Beck Jun 11 '16 at 10:38
  • The other dll's are in the same folder as my dll, but in another folder than the main executable program. The option you are looking for is -static, but I am not allowed to use static linking to the standard libraries. – Shadowwolf Jun 11 '16 at 10:43
  • There is an extra one now: `-static-libstdc++` see more here http://stackoverflow.com/questions/14225083/linking-with-static-libstdc-flag-on-mingw-4-7-1 I don't know if there is an equivalent thing for the `seh` dll. – Chris Beck Jun 11 '16 at 10:59
  • An equivalent exists for the other dll, the option was called -static-libgcc, but as said in the question, static linking is forbidden. So that is not really an option. – Shadowwolf Jun 11 '16 at 11:01
  • You could always call the Windows API function [`SetEnvironmentVariable`](https://msdn.microsoft.com/en-us/library/windows/desktop/ms686206.aspx). The change is _only_ for your process, that is, the variable you change doesn't propagate back to the system settings. – theB Jun 11 '16 at 13:18

1 Answers1

4

If you have no way to statically include those dependencies or modify the PATH to affect the DLL search, you can try another option: just load those dependencies directly using the same package.loadlib call before you load your Module.DLL. I used this in a situation when I wanted to make sure that the DLL my libraries depend on was loaded from the correct location:

package.loadlib([[C:\Path\To\Whatever\libstdc++-6.dll]], "")
init = assert(package.loadlib("C:\\Path\\To\\My\\Module.DLL", "luaopen_MyModule"))
init()
Paul Kulchenko
  • 25,884
  • 3
  • 38
  • 56