[Tutorial] SketchUp Ruby C Extension

[Tutorial] SketchUp Ruby C Extension

Postby thomthom » Fri Nov 04, 2011 11:10 am

Current WIP
https://bitbucket.org/thomthom/sketchup ... -extension

Working OSX and Windows "Hello World" example.




This question comes up from time to time, how to compile a Ruby C Extension that works for SketchUp.

Following tutorials for standard Ruby will not work for SketchUp without modifications. It would be nice if we could properly document this.

For OSX I think I have all the info, thanks to AdamB that explained that it needed to be compiled into a flat namespace: viewtopic.php?f=180&t=28673&start=0#p249370
However, would be nice if anyone knew how to generate a make file with the correct flags so one does not have to edit it manually every time - like I do... :? :oops: )


For Windows it's even more to be done. TBD helped me out here with his Pelles C project. However, I was unable to create and set up a project for compilation myself and I have no idea what is needed to make it compile correctly. I'd like to learn this.

One thing is that the C Extension under windows requires you to install a standard ruby installation and modify config.h to bypass a MSC check. (Or does anyone have a solution that doesn't require this?)

I see Dana is using a make file that seem to be used on both platforms: https://github.com/danawoodman/google-s ... eLists.txt

However, that project doesn't work in SketchUp yet.


So, the short story is, can we (the devs here) put together a step by step tutorial on how to compile a SketchUp Ruby C Extension for OSX and Windows?
(I can write it up, but I need someone to provide with the technical and explains how and why.)
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: SketchUp Ruby C Extension tutorial - can we make one?

Postby tbd » Fri Nov 04, 2011 1:01 pm

can you fork https://github.com/TBD/OpenSUP/tree/master/SUExt and send a pull request for the OSX version ?

will try to make a step by step page for compiling on PellesC (I will not install VStudio on virtual machine ;)
0
SketchUp Ruby Consultant | Podium 1.x developer
http://plugins.ro
User avatar
tbd 
 

Re: SketchUp Ruby C Extension tutorial - can we make one?

Postby thomthom » Fri Nov 04, 2011 1:05 pm

TBD wrote:send a pull request for the OSX version ?

There is an OSX version? I'm not sure what you mean about sending a pull request... :oops:

What would be nice is along with the tutorial we could set up the framework for making and compiling on both platforms with minimum mount of per-platform files. If possible?
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: SketchUp Ruby C Extension tutorial - can we make one?

Postby thomthom » Fri Nov 04, 2011 1:07 pm

I clicked Fork when I was under SUExt - and it forked the whole repository. I guess there is no way to fork a part of a repository... ?
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: SketchUp Ruby C Extension tutorial - can we make one?

Postby thomthom » Fri Nov 04, 2011 1:08 pm

Clicking "Pull Request" and I get a message:

"Oops! The TBD:master branch is already up-to-date with thomthom:master — maybe you want to try something else?"

....I should stop clicking now... :oops:
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: SketchUp Ruby C Extension tutorial - can we make one?

Postby tbd » Fri Nov 04, 2011 1:12 pm

fork - it creates a duplicate of the entire project in your account. you can change only in one subdirectory if you want.
pull request - you make the changes in your forked project and send a pull request so I can integrate your changes

you need to add some changes to send a pull request to me first.
0
SketchUp Ruby Consultant | Podium 1.x developer
http://plugins.ro
User avatar
tbd 
 

Re: SketchUp Ruby C Extension tutorial - can we make one?

Postby thomthom » Fri Nov 04, 2011 1:19 pm

Right. Should I leave the other folders alone?

Just thinking it might be nice with a repo just for C Extension - nothing else. Just to keep it clean and simple. :?:
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: SketchUp Ruby C Extension tutorial - can we make one?

Postby tbd » Fri Nov 04, 2011 1:32 pm

https://github.com/sketchucation is ready to accept projects ;)
0
SketchUp Ruby Consultant | Podium 1.x developer
http://plugins.ro
User avatar
tbd 
 

Re: SketchUp Ruby C Extension tutorial - can we make one?

Postby thomthom » Fri Nov 04, 2011 1:36 pm

TBD wrote:https://github.com/sketchucation is ready to accept projects ;)


Right'o. So can we create an "SketchUp Ruby C Extension" project? Then start adding stuff.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: SketchUp Ruby C Extension tutorial - can we make one?

Postby tbd » Fri Nov 04, 2011 2:02 pm

0
SketchUp Ruby Consultant | Podium 1.x developer
http://plugins.ro
User avatar
tbd 
 

Re: SketchUp Ruby C Extension tutorial - can we make one?

Postby thomthom » Sat Nov 05, 2011 10:36 pm

I just got a very simple Hello World example working under OSX. Will create another example with some basic Ruby object interactions and expand a little on my comments. Then I will upload it to a repository. Think I'll focus on the step by step for OSX first to get the structure up. Then Windows - seem to be a bit more tweaking to get that working.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: SketchUp Ruby C Extension tutorial - can we make one?

Postby Chris Fullmer » Sun Nov 06, 2011 2:34 am

This sounds great Thom and TBD and everyone one else who gets involved. I keep being afraid that I might need to learn some of this for my upcoming work.

Chris
0
Lately you've been tan, suspicious for the winter.
All my Plugins I've written
User avatar
Chris Fullmer 
SketchUp Team
SketchUp Team
 

Re: SketchUp Ruby C Extension tutorial - can we make one?

Postby thomthom » Sun Nov 06, 2011 11:09 am

What you got cooking?
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: SketchUp Ruby C Extension tutorial - can we make one?

Postby thomthom » Sun Nov 06, 2011 2:47 pm

Right - attempting to build on Windows.

I have Visual C++ Express 201 installed and I'm trying to build using nmake. Getting some errors:
Build Error.png


I'm not sure what that means. Though I have a suspicion I need to specify the path to where windows.h is located... Though I don't know where to do so...
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: SketchUp Ruby C Extension tutorial - can we make one?

Postby thomthom » Sun Nov 06, 2011 2:48 pm

Uploaded my WIP at: https://bitbucket.org/thomthom/sketchup ... extension/

Working on OSX 10.5.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: SketchUp Ruby C Extension tutorial - can we make one?

Postby thomthom » Sun Nov 06, 2011 2:50 pm

0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: SketchUp Ruby C Extension tutorial - can we make one?

Postby thomthom » Sun Nov 06, 2011 3:04 pm

Think I got one step further. This thread mentions that vcvars32.bat needs to be run from the prompt: http://social.msdn.microsoft.com/Forums ... 56a2f14cd/

And this (http://stackoverflow.com/questions/6622 ... with-nmake)

So after I did that I got a different error. Missing crt file...
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: SketchUp Ruby C Extension tutorial - can we make one?

Postby thomthom » Sun Nov 06, 2011 3:08 pm

( Apologies for those with the know-how - I will be posting lots of silly stuff as I work through this. Posting to make a record of what I am doing. "Thinking out loud". )
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: SketchUp Ruby C Extension tutorial - can we make one?

Postby thomthom » Sun Nov 06, 2011 3:36 pm

:berserk:

Got it working!

Uncommented a #pragma comment(lib, "crt.lib"); I had. TBD's SUExt project had a reference to it. Which is what I based my project on. Seeing how it also referred to #pragma comment(lib, "msvcrt-ruby18.lib"); I just tried to see what happened if I removed the ref to crt.lib. Everything worked fine after that point.

Now I wonder what the other lines do:

#pragma comment(lib, "kernel32.lib")
#pragma comment(lib, "gdi32.lib")
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "shell32.lib")


I'm looking at this tutorial: http://blogs.law.harvard.edu/hoanga/200 ... n-windows/
It made no reference to any of this. ( what is it? Is it really required? )

I'm guessing #include <windows.h> is required though.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: SketchUp Ruby C Extension tutorial - can we make one?

Postby thomthom » Sun Nov 06, 2011 3:38 pm

Now... I'd like to find a way to make any output from extconf.rb and make/nmake put everything is a separate directory - for each platform.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: SketchUp Ruby C Extension tutorial - can we make one?

Postby thomthom » Sun Nov 06, 2011 4:02 pm

Huh... I removed all of that stuff completely, as http://blogs.law.harvard.edu/hoanga/200 ... n-windows/ made no reference to it at all. Worked fine without. Guess it was required due to the way the Pelles C project was set up... :?:
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Tutorial] SketchUp Ruby C Extension

Postby thomthom » Sun Nov 06, 2011 4:46 pm

Hey Chris, when we get around to writing up the step by step instructions, are you willing to be a guinea pig?
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Tutorial] SketchUp Ruby C Extension

Postby Chris Fullmer » Sun Nov 06, 2011 10:25 pm

Absolutely!
0
Lately you've been tan, suspicious for the winter.
All my Plugins I've written
User avatar
Chris Fullmer 
SketchUp Team
SketchUp Team
 

Re: [Tutorial] SketchUp Ruby C Extension

Postby thomthom » Sun Nov 06, 2011 11:37 pm

Great!

I'm writing up a Basic example that shows a little more than Hello World.

Then I start on making the step by step Wiki tutorial. I hope people with more know how can fill the in the "why" to much of it. And that people will try it and give feedback on what is unclear and what turns out not to work.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: SketchUp Ruby C Extension tutorial - can we make one?

Postby Dan Rathbun » Mon Nov 07, 2011 5:02 am

thomthom wrote:Though I have a suspicion I need to specify the path to where windows.h is located... Though I don't know where to do so...

To do so via the IDE... from the menu Tools > Options...

.. brings up the "Options" dialog.
Choose "VC++ Directories" from the "Projects and Solutions" branch in the nav tree.
You can see the dirs for catagories by selecting the cat from the "Show directories for:" dropdown control:

Executable files:
VCpp_opts_exe.png


Include files:
VCpp_opts_inc.png
0
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    Re: [Tutorial] SketchUp Ruby C Extension

    Postby Dan Rathbun » Mon Nov 07, 2011 5:10 am

    Don't forget the "help" topic here:
    [Info] C/C++ Ruby extensions & SketchUp plugins
    .. and read Adan Nelson's posts (links on the above list.)
    0
      I'm not here much anymore. But a PM will fire email notifications.
      User avatar
      Dan Rathbun 
      PluginStore Author
      PluginStore Author
       

      Re: [Tutorial] SketchUp Ruby C Extension

      Postby Dan Rathbun » Tue Nov 08, 2011 11:37 pm

      from the info file "win32.readme" in the Ruby C source:
      You can NOT use a path name [that] contains any white space characters as
      the ruby source directory, this restriction comes from the behavior of include directives of NMAKE.
      (- you may call it a bug. -)
      0
        I'm not here much anymore. But a PM will fire email notifications.
        User avatar
        Dan Rathbun 
        PluginStore Author
        PluginStore Author
         

        Re: [Tutorial] SketchUp Ruby C Extension

        Postby tbd » Wed Nov 09, 2011 8:31 am

        Thom: #pragma comment(lib, "*.lib") adds the libraries to the link phase (that hold imports and functions code)

        it was a way to make sure that it will compile even if you create a new project and don't use in mine in PellesC.
        0
        SketchUp Ruby Consultant | Podium 1.x developer
        http://plugins.ro
        User avatar
        tbd 
         

        Re: [Tutorial] SketchUp Ruby C Extension

        Postby thomthom » Wed Nov 09, 2011 8:36 am

        Right'o! Gotcha. Been reading more up on C and GCC.
        0
        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund
        User avatar
        thomthom 
        PluginStore Author
        PluginStore Author
         

        Re: [Tutorial] SketchUp Ruby C Extension

        Postby tomasz » Wed Nov 09, 2011 2:44 pm

        Thanks Thomas for the example.

        I do not understand what is 'extconf.rb' for. I have compiled my extension under VC++ 2008 without running the file and without using any makefile... Is it bad ? :? :mrgreen:
        0

        tomasz 
        SU2TH & SU2KT Developer
         

        SketchUcation One-Liner Adverts

        by Ad Machine » 5 minutes ago



        Ad Machine 
        Robot
         

        Next


         

        Return to Developers' Forum

        Who is online

        Users browsing this forum: DirkSander and 10 guests

        Visit our sponsors: