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

**URL:** <https://forums.sketchup.com/t/loading-a-native-extension-through-ruby-which-depends-on-other-dlls/6753>\
**Category:** Developers\
**Created:** [February 6, 2015, 9:04am UTC](https://forums.sketchup.com/t/loading-a-native-extension-through-ruby-which-depends-on-other-dlls/6753 "2015-02-06T09:04:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hgschutte1](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/hgschutte1/32/2915_2.png) [@hgschutte1](https://forums.sketchup.com/u/hgschutte1)\
**Post date:** [February 6, 2015, 9:04am UTC](https://forums.sketchup.com/t/loading-a-native-extension-through-ruby-which-depends-on-other-dlls/6753/1 "2015-02-06T09:04:09Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![bugra](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/bugra/32/33481_2.png) [@bugra](https://forums.sketchup.com/u/bugra)\
**Post date:** [February 6, 2015, 2:40pm UTC](https://forums.sketchup.com/t/loading-a-native-extension-through-ruby-which-depends-on-other-dlls/6753/2 "2015-02-06T14:40:50Z")

</div>

This is due to the complicated search rules Windows has to locate DLLs (see [here](https://msdn.microsoft.com/en-us/library/windows/desktop/ms682586%28v=vs.85%29.aspx)). One thing you can do is call the Win32 API function [SetDllDirectory](https://msdn.microsoft.com/en-us/library/windows/desktop/ms686203%28v=vs.85%29.aspx) 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](https://msdn.microsoft.com/en-us/library/windows/desktop/ms683186%28v=vs.85%29.aspx), 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  
😒

---

<div class="post-metadata">

**Author:** ![hgschutte1](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/hgschutte1/32/2915_2.png) [@hgschutte1](https://forums.sketchup.com/u/hgschutte1)\
**Post date:** [February 7, 2015, 10:25pm UTC](https://forums.sketchup.com/t/loading-a-native-extension-through-ruby-which-depends-on-other-dlls/6753/3 "2015-02-07T22:25:08Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![Marsh](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@Marsh](https://forums.sketchup.com/u/Marsh)\
**Post date:** [November 18, 2015, 9:14pm UTC](https://forums.sketchup.com/t/loading-a-native-extension-through-ruby-which-depends-on-other-dlls/6753/4 "2015-11-18T21:14:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nintari](https://avatars.discourse-cdn.com/v4/letter/n/50afbb/32.png) [@nintari](https://forums.sketchup.com/u/nintari)\
**Post date:** [December 16, 2015, 12:47am UTC](https://forums.sketchup.com/t/loading-a-native-extension-through-ruby-which-depends-on-other-dlls/6753/5 "2015-12-16T00:47:27Z")

</div>

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