# Ruby Extension/DLL Help

**URL:** <https://rubytalk.org/t/ruby-extension-dll-help/8820>\
**Category:** ruby-talk\
**Created:** [16 November 2003 19:51 UTC](https://rubytalk.org/t/ruby-extension-dll-help/8820 "2003-11-16T19:51:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andy\_Pelzer](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Andy\_Pelzer](https://rubytalk.org/u/Andy_Pelzer)\
**Post date:** [16 November 2003 19:51 UTC](https://rubytalk.org/t/ruby-extension-dll-help/8820/1 "2003-11-16T19:51:32Z")

</div>

Hi,

Recently i started writing a Ruby extension. This Extension is providing  
access to a dll-library. It has been written in c. Compiling works fine,  
but using it in Ruby always raises this error: “dlsym: win32 error 127  
[…] (LoadError)”. What does this error mean? I think it means, that  
Ruby cannot find the dll, used by the extension, but i’m absolutely  
unsure. If this is correct, where does the dll have to be? If not, what  
does this error mean? Any suggestions how to fix this?

Environment: Ruby 1.8 on WinXp/Cygwin, compiler: gcc/make

Would be great if anybody could help, i’m absolutely stuck with that.

Many thanks in advance (and please excuse my bad english)

Greets

Andy

---

<div class="post-metadata">

**Author:** ![Michael\_Davis1](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@Michael\_Davis1](https://rubytalk.org/u/Michael_Davis1)\
**Post date:** [17 November 2003 02:53 UTC](https://rubytalk.org/t/ruby-extension-dll-help/8820/2 "2003-11-17T02:53:39Z")

</div>

I think there is an issue with cygwin on XP. I am not sure if the issue is with cygwin or XP. However, libraries built on cygwin using gcc will not load with Ruby on XP, the same code worked great on windows 2000 with cygwin but not on XP. In the end, I had to create the DLL using MS Visual C++ and put the DLL in c:\winnt\systems (or c:\windows\system). Once this was done, I used win32api to successfully access functions in the library.

Hope this helps, Michael Davis

Andy Pelzer wrote:

> **···**
>
> > Hi,
> > 
> > Recently i started writing a Ruby extension. This Extension is providing  
> > access to a dll-library. It has been written in c. Compiling works fine,  
> > but using it in Ruby always raises this error: “dlsym: win32 error 127  
> > […] (LoadError)”. What does this error mean? I think it means, that  
> > Ruby cannot find the dll, used by the extension, but i’m absolutely  
> > unsure. If this is correct, where does the dll have to be? If not, what  
> > does this error mean? Any suggestions how to fix this?
> > 
> > Environment: Ruby 1.8 on WinXp/Cygwin, compiler: gcc/make
> > 
> > Would be great if anybody could help, i’m absolutely stuck with that.
> > 
> > Many thanks in advance (and please excuse my bad english)
> > 
> > Greets
> > 
> > Andy

---

<div class="post-metadata">

**Author:** ![Andy\_Pelzer1](https://avatars.discourse-cdn.com/v4/letter/a/d6d6ee/32.png) [@Andy\_Pelzer1](https://rubytalk.org/u/Andy_Pelzer1)\
**Post date:** [17 November 2003 23:08 UTC](https://rubytalk.org/t/ruby-extension-dll-help/8820/3 "2003-11-17T23:08:34Z")

</div>

Hi,

> > In the end, I had to create the DLL using MS Visual C++ and put the  
> > DLL in c:\winnt\systems (or c:\windows  
> > \system).  
> > Since i don’t have MSVC i couldn’t test it your way. So i tried with  
> > MinGW (which is delivered with Dev-C++), but couldn’t manage to get my  
> > extension compiled. Have to “investigate” a bit (-\> read manual _g_),  
> > seems MinGW doesn’t accept include-paths with -I on command line??

> > I think there is an issue with cygwin on XP. I am not sure if the  
> > issue is with cygwin or XP.  
> > Are you sure about the CygWin\<-\>XP issue? I have another extension (not  
> > using an additional/external dll), which compiles fine and also works  
> > with Ruby under CygWin/XP (found an extension-example here:  
> > [http://www.bagley.org/~doug/shootout/compare/binext/ruby/Ackermann](http://www.bagley.org/~doug/shootout/compare/binext/ruby/Ackermann) →   
> > working!).

> > Once this was done, I used win32api to successfully access functions  
> > in the library.  
> > Why use Win32api to access the dll’s functions? I have a dll-library,  
> > provided by somebody else - no code available to me, so i wrote simple  
> > “access-functions” in c, as an extension for Ruby. Am i mistaking  
> > something here?

Anyways, thanks again, i’ll keep on trying [ though not much time for it  
;( ]

Greets

Andy

---

<div class="post-metadata">

**Author:** ![Michael\_Davis1](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@Michael\_Davis1](https://rubytalk.org/u/Michael_Davis1)\
**Post date:** [18 November 2003 03:51 UTC](https://rubytalk.org/t/ruby-extension-dll-help/8820/4 "2003-11-18T03:51:04Z")

</div>

See comments below…

Andy Pelzer wrote:

> Hi,
> 
> > > In the end, I had to create the DLL using MS Visual C++ and put the
> 
> DLL in c:\winnt\systems (or c:\windows
> 
> > > \system).
> 
> Since i don’t have MSVC i couldn’t test it your way. So i tried with  
> MinGW (which is delivered with Dev-C++), but couldn’t manage to get my  
> extension compiled. Have to “investigate” a bit (-\> read manual _g_),  
> seems MinGW doesn’t accept include-paths with -I on command line??

Bummer.

> > > I think there is an issue with cygwin on XP. I am not sure if the
> 
> issue is with cygwin or XP.  
> Are you sure about the CygWin\<-\>XP issue? I have another extension (not  
> using an additional/external dll), which compiles fine and also works  
> with Ruby under CygWin/XP (found an extension-example here:  
> [http://www.bagley.org/~doug/shootout/compare/binext/ruby/Ackermann](http://www.bagley.org/~doug/shootout/compare/binext/ruby/Ackermann) →   
> working!).

No, I am not sure. I bailed on trying to figure out where the error was occurring after a few hours of debugging and opted for a different approach. It could have been a compiler setting or an include path for the libraries.

> > > Once this was done, I used win32api to successfully access functions
> 
> in the library.  
> Why use Win32api to access the dll’s functions? I have a dll-library,  
> provided by somebody else - no code available to me, so i wrote simple  
> “access-functions” in c, as an extension for Ruby. Am i mistaking  
> something here?

I used Win32api to eliminate the need to write a C wrapper for the DLL functions I wanted to use. The C wrapper may have performed a little better but would have required a little more work on my part. One of my goals was to eliminate the need to compile any C code.

> Anyways, thanks again, i’ll keep on trying [ though not much time for it  
> ;( ]
> 
> Greets
> 
> Andy

See comments above…

Thanks, Michael
