Cannot get C extensions to run in Sketchup
-
Hi folks,
I've had some good luck running the Oily_PNG extension (https://github.com/wvanbergen/oily_png) with Sketchup, and I'm at the point where I'd like to start writing my own C extensions, and so far I've found things to be...difficult. I'm starting at a very basic level - just building a simple "hello world" program, compiling it (via Cygwin), then trying to load the .so extension into Sketchup. It compiles just fine, runs fine on its own, and runs fine if I tuck it into a little ruby script and run it through Cygwin's command line. If I try to load it via Sketchup, however, it kicks out the following error:require "C:/code/myext"
Error: #<LoadError: 126: The specified module could not be found. - C:/code/myext.so>
C:/Program Files/SketchUp/SketchUp 2016/Tools/RubyStdLib/rubygems/core_ext/kernel_require.rb:45:inrequire' C:/Program Files/SketchUp/SketchUp 2016/Tools/RubyStdLib/rubygems/core_ext/kernel_require.rb:45:in
require'
<main>:in<main>' SketchUp:1:in
eval'I have no idea what the issue is, or where to even begin. Can someone out there with some experience point me in the right direction? Thanks!
-
You will want to check out this Github repository[1]
I hope someone who knows better will correct me, but it is my current understanding that you will need Visual Studio 2010 in order to build compatible .dll files for SketchUp plugins on Windows.
-
Thanks Jim,
I've got that one - I didn't have much luck with it the first go-round but I'll give it another shot and see if maybe I've learned some stuff since I last tried. -
I've nosed around in there and Hello World seems to compile okay on Visual Studio (2015, in my case) but I have no idea what to actually do with any of it - I was hoping for something more of a walkthrough in terms of:
- Here's the example repository
- Here's what to do to compile it (i.e. compile it via Visual Studio, etc.)
- Here's the output that you'll need (directory, .so file, etc.)
- Here's how to talk to it with Ruby and make use of it in Sketchup (i.e. put out a UI messagebox with "Hello World")
I hope I'm not missing anything incredibly obvious, but it's not clear to me as a novice how to progress forward with these materials.
-
Curiously, if I compile on a Linux machine, I'm not seeing any joy, but I'm getting a different error:
require "C:/code/myext/myext"
Error: #<LoadError: 193: %1 is not a valid Win32 application. - C:/code/myext/myext.so>
C:/Program Files/SketchUp/SketchUp 2016/Tools/RubyStdLib/rubygems/core_ext/kernel_require.rb:45:inrequire' C:/Program Files/SketchUp/SketchUp 2016/Tools/RubyStdLib/rubygems/core_ext/kernel_require.rb:45:in
require'
<main>:in<main>' SketchUp:1:in
eval' -
@johnzdennis said:
Curiously, if I compile on a Linux machine, I'm not seeing any joy, but I'm getting a different error:
require "C:/code/myext/myext"
Error: #<LoadError: 193: %1 is not a valid Win32 application. - C:/code/myext/myext.so>
C:/Program Files/SketchUp/SketchUp 2016/Tools/RubyStdLib/rubygems/core_ext/kernel_require.rb:45:inrequire' C:/Program Files/SketchUp/SketchUp 2016/Tools/RubyStdLib/rubygems/core_ext/kernel_require.rb:45:in
require'
<main>:in<main>' SketchUp:1:in
eval'Sounds like you are trying to load a 32bit binary in 64bit SketchUp - or vise-versa. Make sure you check what build config you use. You need to generate separate binaries per bitness. And make sure you aren't trying to load Ruby 1.8 builds in SU versions using Ruby 2.0.
-
@johnzdennis said:
but I have no idea what to actually do with any of it
Do you have something specific in mind for what you want to use Ruby C Extensions for?
-
Thanks - I'll give that a look and see. I originally discounted it since Oily_PNG has survived several Sketchup updates without going sour on me, but it's definitely worth inspecting.
As far as my purposes, most of what I'm doing will have to do with pixel counting and generating overlay images of PNG's. I can do it fine in Ruby but it's slow; when dealing with larger images I really want something that can kick it into higher gear.
-
Well that was hell in a bucket. Thom's advice looks like it was solid; I'd forgotten that I had to install oily_png as a ruby gem and in doing so it compiled for Ruby 2.0.0; that's why it worked. So far I've tried repackaging some C code as a gem and then installing it so it uses the 2.0.0 compiler; that gets a "true" response when I require it from the Sketchup ruby console, so...hooray. Seems like I'm making progress.
-
@johnzdennis said:
As far as my purposes, most of what I'm doing will have to do with pixel counting and generating overlay images of PNG's. I can do it fine in Ruby but it's slow; when dealing with larger images I really want something that can kick it into higher gear.
So you want a C/C++ lib to handle this image manipulation and wrap with with Ruby?
-
That's the plan.
Advertisement