Loading a native extension through Ruby which depends on other .dlls

Hey, all. I’m trying to load a Ruby extension compiled as .dll (aliased through the .so extension). I used the example found as a basis within the SDK, and this worked great until I began linking a few Qt libraries.

In a nutshell, the Qt libraries depend on .dll files, and every time I try to load the extension through the Ruby console, this message pops out:

LoadError: 126: The specified module could not be found.   - C:/ProgramData/SketchUp/SketchUp 2015/SketchUp/Plugins/my_extension.so

So far, I’ve tried things like setting the RUBYLIB environment variable, as well as placing the .dll dependencies in the location provided by echoing Config::CONFIG['bindir']:

bindir => C:/Program Files (x86)/SketchUp/SketchUp 2015/Tools/bin

Creating the bin/ directory in the Tools folder and placing the dependencies there didn’t yield any results either.

Any advice on this?

This is due to the complicated search rules Windows has to locate DLLs (see here). One thing you can do is call the Win32 API function SetDllDirectory to temporarily point it to the directory where Qt DLLs are located. You then would have to set it back to what it was or else you could break SketchUp or other plugins. So you would first have to get the original search path via GetDllDirectory, point it to your directory, load your .so file and restore the original search path with a second call to SetDllDirectory. Overall, it’s a real pain with lots of subtle ways to get it wrong
:unamused:

Yeah, those search rules aren’t very explicit by any means either >.<

What you suggested worked well, though. Thanks a ton.

I am having a similar issue when trying to load dlls which require other dlls using Fiddle. Is there a better solution for this? I need it to load dlls from several separate paths and would prefer not to use this hack. I tried adding my directories to the ruby $LOAD_PATH but that did not seem to work.

Urgh… I don’t suppose there’s some sample code out there for this task…