# Problem on C ruby extension

**URL:** <https://forums.sketchup.com/t/problem-on-c-ruby-extension/31386>\
**Category:** Developers\
**Created:** [September 27, 2016, 3:46am UTC](https://forums.sketchup.com/t/problem-on-c-ruby-extension/31386 "2016-09-27T03:46:59Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ikamei](https://avatars.discourse-cdn.com/v4/letter/i/c77e96/32.png) [@ikamei](https://forums.sketchup.com/u/ikamei)\
**Post date:** [September 27, 2016, 3:46am UTC](https://forums.sketchup.com/t/problem-on-c-ruby-extension/31386/1 "2016-09-27T03:46:59Z")

</div>

hi all:  
i have some functions already in c, and want to provide ruby interfaces that can be used in sketchup 2014’s ruby console. os is win7  
what i am done:

- download ruby source code : ruby-2.0.0-p247.tar.bz2
- compile it use vs 2008 x86,
- wrap my c functions, and write a extconf.rb
- use ruby-2.0.0-p247/build/bin/ruby.exe extconf.rb to generate a dll ( ext\_ruby.so )
- 

> ruby-2.0.0-p247/build/bin/irb  
> require ‘somepath/ext\_ruby’ work

but when load ext\_ruby.so in sketchup’s console.  
it compains error 126.  
and copy msvcr90-ruby200.dll to c:/program files(x86)/sketchup/sketchup2014 folder  
it complains incompatible library version

so, some one give me a direction ? or there have a tutorial do the same thing ?  
many thanks

---

<div class="post-metadata">

**Author:** ![ikamei](https://avatars.discourse-cdn.com/v4/letter/i/c77e96/32.png) [@ikamei](https://forums.sketchup.com/u/ikamei)\
**Post date:** [September 27, 2016, 3:10pm UTC](https://forums.sketchup.com/t/problem-on-c-ruby-extension/31386/2 "2016-09-27T15:10:05Z")

</div>

solved by using correct ruby library

> **[ruby-c-extension-examples/ThirdParty at main ·...](https://github.com/SketchUp/ruby-c-extension-examples/tree/main/ThirdParty)**
>
> main/ThirdParty

---

<div class="post-metadata">

**Author:** ![molnar.a.hu](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@molnar.a.hu](https://forums.sketchup.com/u/molnar.a.hu)\
**Post date:** [January 7, 2017, 11:01pm UTC](https://forums.sketchup.com/t/problem-on-c-ruby-extension/31386/3 "2017-01-07T23:01:57Z")

</div>

Hi!  
I’ve written a C program which runs good as an exe, and would like to create a Sketchup Extension from it… I’ve tried to start with the github HelloWorld project, but did not manage to create the appropriate rb file to get it work… I recieve an error message:

Error: 193: %1 ist keine zulässige Win32-Anwendung. - path of .so file  
which means “is no valid” Win-32 application…

what did I do wrong?

see also:

> <https://github.com/SketchUp/ruby-c-extension-examples/issues/13>
>
> Hi,
> I'm trying to get this HelloWorld project for SketchUp running with win7 wi…th VS 2015 and SU2016 - I t I do it would try it without "SWING"
> without success...
> I'm missing the ruby code or extension; that would run .so file, and did not manage to make it based on the SketchUp extension su\_create\_layout\_file...
> 
> the same problem the other way around:
> \*\*I've written a C program which runs good as an exe, and would like to create a Sketchup Extension from it... I've tried to start with the github HelloWorld project, but did not manage to create the appropriate rb file to get it work... I recieve an error message:
> 
> Error: 193: %1 ist keine zulässige Win32-Anwendung. - path of .so file
> which means "is no valid" Win-32 application....
> 
> what did I do wrong?\*\*
> 
> Could you give me any clue please...
> Thanks in advance!
> 
> see also:
> https://forums.sketchup.com/t/problem-on-c-ruby-extension/31386/3

---

<div class="post-metadata">

**Author:** ![jim\_foltz](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/jim_foltz/32/74787_2.png) [@jim\_foltz](https://forums.sketchup.com/u/jim_foltz)\
**Post date:** [January 9, 2017, 8:28am UTC](https://forums.sketchup.com/t/problem-on-c-ruby-extension/31386/4 "2017-01-09T08:28:00Z")

</div>

Make sure you are compiling the appropriate target for your machine - Win32 or 64 bit.

---

<div class="post-metadata">

**Author:** ![molnar.a.hu](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@molnar.a.hu](https://forums.sketchup.com/u/molnar.a.hu)\
**Post date:** [January 9, 2017, 3:37pm UTC](https://forums.sketchup.com/t/problem-on-c-ruby-extension/31386/5 "2017-01-09T15:37:46Z")

</div>

Thanks Jim,  
In fact I’m able to run the exe file even from ruby console in SU with “system”, but I’d like to go a step further…  
… to be able to “require” the compiled executable and to run a specific command in it. (and passing arguments like in the su\_create\_layout\_file extension…)  
I’m not a “real software engineer”, so it might still be that your hint to win32 and win64 is correct…

---

<div class="post-metadata">

**Author:** ![slbaumgartner](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/slbaumgartner/32/7302_2.png) [@slbaumgartner](https://forums.sketchup.com/u/slbaumgartner)\
**Post date:** [January 9, 2017, 3:40pm UTC](https://forums.sketchup.com/t/problem-on-c-ruby-extension/31386/6 "2017-01-09T15:40:23Z")

</div>

> [@molnar.a.hu](#):
>
> to be able to “require” the compiled executable

This may be the base of your problem. You can “require” a Ruby or a compiled Ruby extension dll, you can’t “require” an .exe.

---

<div class="post-metadata">

**Author:** ![molnar.a.hu](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@molnar.a.hu](https://forums.sketchup.com/u/molnar.a.hu)\
**Post date:** [January 9, 2017, 3:47pm UTC](https://forums.sketchup.com/t/problem-on-c-ruby-extension/31386/7 "2017-01-09T15:47:04Z")

</div>

> [@slbaumgartner](#):
>
> compiled Ruby extension dll

this point is clear!  
BUT  
how to get a VisualStudio Project converted to a compiled ruby extension???

I thought to learn it by

> <https://github.com/SketchUp/ruby-c-extension-examples/tree/main/Hello%20World>
>
> //github.com/SketchUp/ruby-c-extension-examples/tree/main/Hello%20World

but if I compile that project, and try by require, I get the above error message…

---

<div class="post-metadata">

**Author:** ![slbaumgartner](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/slbaumgartner/32/7302_2.png) [@slbaumgartner](https://forums.sketchup.com/u/slbaumgartner)\
**Post date:** [January 9, 2017, 3:48pm UTC](https://forums.sketchup.com/t/problem-on-c-ruby-extension/31386/8 "2017-01-09T15:48:58Z")

</div>

I’m on a Mac, so I’ll have to defer to a Windows expert regarding Visual Studio setup to compile a Ruby extension dll vs an executable .exe.

---

<div class="post-metadata">

**Author:** ![molnar.a.hu](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@molnar.a.hu](https://forums.sketchup.com/u/molnar.a.hu)\
**Post date:** [January 12, 2017, 3:13pm UTC](https://forums.sketchup.com/t/problem-on-c-ruby-extension/31386/9 "2017-01-12T15:13:32Z")

</div>

Thanks for contributions - pls follow the discussion at:

> <https://github.com/SketchUp/ruby-c-extension-examples/issues/13>
>
> Hi,
> I'm trying to get this HelloWorld project for SketchUp running with win7 wi…th VS 2015 and SU2016 - I t I do it would try it without "SWING"
> without success...
> I'm missing the ruby code or extension; that would run .so file, and did not manage to make it based on the SketchUp extension su\_create\_layout\_file...
> 
> the same problem the other way around:
> \*\*I've written a C program which runs good as an exe, and would like to create a Sketchup Extension from it... I've tried to start with the github HelloWorld project, but did not manage to create the appropriate rb file to get it work... I recieve an error message:
> 
> Error: 193: %1 ist keine zulässige Win32-Anwendung. - path of .so file
> which means "is no valid" Win-32 application....
> 
> what did I do wrong?\*\*
> 
> Could you give me any clue please...
> Thanks in advance!
> 
> see also:
> https://forums.sketchup.com/t/problem-on-c-ruby-extension/31386/3

(if interested 🙂

---

<div class="post-metadata">

**Author:** ![TommyK](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tommyk/32/2998_2.png) [@TommyK](https://forums.sketchup.com/u/TommyK)\
**Post date:** [May 4, 2017, 4:39pm UTC](https://forums.sketchup.com/t/problem-on-c-ruby-extension/31386/10 "2017-05-04T16:39:25Z")

</div>

I am having issues with incompatible library version within Sketchup 2017 too:

```
Error Loading File /Users/***/Library/Application Support/SketchUp 2017/SketchUp/Plugins/MyPlugin/core.rb
Error: #<fatal: incompatible library version - /Users/***/Library/Application Support/SketchUp 2017/SketchUp/Plugins/MyPlugin/SUEX_MyPlugin.bundle>
/Applications/SketchUp 2017/SketchUp.app/Contents/Frameworks/Ruby.framework/Versions/2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Applications/SketchUp 2017/SketchUp.app/Contents/Frameworks/Ruby.framework/Versions/2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'

```

I can run my plugin for SU2016 with Ruby 2.0, but I can’t get past the error above with SU2017. I am using Ruby 2.0 Framework for SU2016, and Ruby 2.2 for SU2017. I have tried as much as possible to emulate the settings and use files from this project: [GitHub - SketchUp/ruby-c-extension-examples: Ruby C extension examples](https://github.com/SketchUp/ruby-c-extension-examples)

… but no luck. I think I really need help!
