Shadowwolf
Shadowwolf

Reputation: 983

Lua DLL Library Dependencies

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.

Upvotes: 1

Views: 1160

Answers (1)

Paul Kulchenko
Paul Kulchenko

Reputation: 26744

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()

Upvotes: 4

Related Questions