• Login
sketchucation logo sketchucation
  • Login
πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

[Tutorial] SketchUp Ruby C Extension

Scheduled Pinned Locked Moved Developers' Forum
176 Posts 16 Posters 25.9k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    AdamB
    last edited by 3 Dec 2012, 10:12

    @thomthom said:

    I take it that the OS Ruby versions is much newer now - and IΒ΄d have to link the build to something other than the OS Ruby?

    No, a Plugin resolves the symbols on load.

    @thomthom said:

    Also, when compiling a C Extension under Mountain Lion - how backwards compatible will it be?

    As much as you ask for it to be: eg -mmacosx-version-min=10.4 will ensure it runs on 10.4 and up.

    @thomthom said:

    I should add some warning about the -Ox flag that it might cause problems - since it's very aggressive optimization.

    Just to correct this. The optimization does not produce 'wrong code' per se. Its that it commonly will remove leaf function stack frames to increase performance, meaning Ruby's GC can't find a reference to a Object and it gets marked for collection. So ensure you keep references and you'll be fine.

    Developer of LightUp Click for website

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 3 Dec 2012, 11:49

      @adamb said:

      No, a Plugin resolves the symbols on load.

      Really? But if the OS Ruby is 1.9, and I compile without doing anything. Won't it be compiled for 1.9 only then? Isn't there completely different functions between 1.8 and 1.9?

      @adamb said:

      As much as you ask for it to be: eg -mmacosx-version-min=10.4 will ensure it runs on 10.4 and up.

      Where does this flag go in the compile process? In the MAKEFILE? In the arguments of the make command?
      (I'm very green to this.)

      @adamb said:

      Just to correct this. The optimization does not produce 'wrong code' per se. Its that it commonly will remove leaf function stack frames to increase performance, meaning Ruby's GC can't find a reference to a Object and it gets marked for collection. So ensure you keep references and you'll be fine.

      Thanks for the clarification.

      Thomas Thomassen β€” SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • T Offline
        thomthom
        last edited by 4 Jan 2013, 12:55

        @designingcrime said:

        Hey guys, so I finally got a Ruby C extension to compile on both os x and windows and link curllib. I got a lot of help from Luis at the RubyInstaller group and ended up using RubyInstaller and DevKit to link curl and build using the gcc compiler included with devkit.
        Here is the extension. Its a modified version of Dana's sketchup downloader, but also included uploading, basic http authentication and ssl certificate checking(all through curl). I provided instructions on how to build on both os x and windows.

        https://github.com/sunglass/SunglassPlugins/tree/master/SG-SketchupHook/src/Connection%20Manager

        Thanks for all your help guys.

        Dana - Lets get your Sketchup downloader plugin working.

        Link is dead. 😞

        Thomas Thomassen β€” SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • W Offline
          Whaat
          last edited by 29 Oct 2013, 16:38

          Just wanted to thank Thomas and everyone else for the contributions in this thread. I tried to get Thomas' Hello World extension working and had no problems at all, thanks to his clear documentation.

          My next experiment will be to incorporate SketchUp SDK calls into the Ruby Extension. Has anyone done this? Is it relatively straightforward? Any 'gotchas' that you could warn me about? Thanks

          SketchUp Plugins for Professionals

          1 Reply Last reply Reply Quote 0
          • W Offline
            Whaat
            last edited by 30 Oct 2013, 05:17

            Problems already...
            I have the SDK .h files installed in the same folder as 'SX_HelloWorld.c'. I'm not sure what to do with the binary files provided with the SDK.

            I tried to include just one header <slapi/model/model.h> file from the SDK and this was the result.

            Feeling clueless...


            test1.jpg

            SketchUp Plugins for Professionals

            1 Reply Last reply Reply Quote 0
            • T Offline
              tt_su
              last edited by 31 Oct 2013, 18:53

              We're actually working on a Hello World example for Visual Studio and Xcode for compiling Ruby C/C++ Extensions for SketchUp. We can expand that (create a work or extra branch) with SLAPI configured as well.

              By the way can you post a Gist of your code? You got some syntax errors there that appear to not be related to linking to the correct headers.

              1 Reply Last reply Reply Quote 0
              • W Offline
                Whaat
                last edited by 31 Oct 2013, 19:14

                @tt_su said:

                We're actually working on a Hello World example for Visual Studio and Xcode for compiling Ruby C/C++ Extensions for SketchUp. We can expand that (create a work or extra branch) with SLAPI configured as well.

                By the way can you post a Gist of your code? You got some syntax errors there that appear to not be related to linking to the correct headers.

                Interesting, I was just now doing some research into 'extconf.rb' and I'm starting to think my problem is related to not configuring the location of the .lib and .h files inside of 'extconf.rb' using the 'dir_config' and 'have_library' commands.

                BTW, the only difference between my code and your 'hello world' code on bitbucket is that I #included one the SLAPI .h files at the top.

                I had assumed (or hoped) that it would be properly linked since I put the files in the same location as the .c file that I was trying to compile. πŸ‘Š

                It goes without saying that I am a complete noob at this.

                SketchUp Plugins for Professionals

                1 Reply Last reply Reply Quote 0
                • T Offline
                  tt_su
                  last edited by 7 Nov 2013, 10:45

                  Hi Dale

                  I looked into this and found that you cannot use Visual Studio's nmake for this as it's C89 - and the SLAPI is written in C99.

                  It would work if you install the DevKit at Ruby Windows Installer - though I'm still working out some minor quirks. We're preparing some Hello World examples to get started with Ruby C Extensions. Can you hang in there a little bit more?

                  1 Reply Last reply Reply Quote 0
                  • W Offline
                    Whaat
                    last edited by 7 Nov 2013, 14:10

                    @tt_su said:

                    Hi Dale

                    I looked into this and found that you cannot use Visual Studio's nmake for this as it's C89 - and the SLAPI is written in C99.

                    It would work if you install the DevKit at Ruby Windows Installer - though I'm still working out some minor quirks. We're preparing some Hello World examples to get started with Ruby C Extensions. Can you hang in there a little bit more?

                    No problem. Thanks for looking into this. I am excited to see the new examples... πŸŽ‰

                    SketchUp Plugins for Professionals

                    1 Reply Last reply Reply Quote 0
                    • T Offline
                      tt_su
                      last edited by 8 Nov 2013, 10:59

                      Good news is that I got the SLAPI example compiling under OSX. I need to test on Windows and clean up the extconf.rb file a little.

                      1 Reply Last reply Reply Quote 0
                      • W Offline
                        Whaat
                        last edited by 8 Nov 2013, 14:51

                        @tt_su said:

                        Good news is that I got the SLAPI example compiling under OSX. I need to test on Windows and clean up the extconf.rb file a little.

                        Cool! πŸ‘

                        SketchUp Plugins for Professionals

                        1 Reply Last reply Reply Quote 0
                        • T Offline
                          tomasz
                          last edited by 8 Nov 2013, 16:34

                          @tt_su said:

                          Good news is that I got the SLAPI example compiling under OSX. I need to test on Windows and clean up the extconf.rb file a little.

                          It will be very good indeed to have those examples easy to compile and ready to expand.

                          Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

                          1 Reply Last reply Reply Quote 0
                          • C Offline
                            cncmachineguy
                            last edited by 16 Nov 2013, 17:34

                            Hello All,
                            I am just starting on C extensions for SU and have a quick question. I have been successful following Thom's hello world example on bit bucket. My first question is are there any known IDE solutions to compile from? I don't relish the idea of writing code in notepad++ or other, then compiling from command line, then loading into SU and hoping it works.
                            Is this the way this is being done now or have I missed something?
                            In any event, THANK you all for the hard work you have put into this so far, if this is the best known solution, I will follow it.

                            BTW, working within Win7(64)

                            1 Reply Last reply Reply Quote 0
                            • T Offline
                              tt_su
                              last edited by 17 Nov 2013, 11:46

                              We are setting up a C++ Hello World example for Visual Studio and Xcode. That will give you better environments to work and debug in.

                              1 Reply Last reply Reply Quote 0
                              • C Offline
                                cncmachineguy
                                last edited by 17 Nov 2013, 14:07

                                Thanks Thomas, I offer to do testing if you need it. Otherwise I will keep my eye on this.

                                1 Reply Last reply Reply Quote 0
                                • C Offline
                                  cncmachineguy
                                  last edited by 18 Nov 2013, 03:31

                                  Not allowed to PM yet, but email has been sent

                                  1 Reply Last reply Reply Quote 0
                                  • 1
                                  • 2
                                  • 5
                                  • 6
                                  • 7
                                  • 8
                                  • 9
                                  • 9 / 9
                                  • First post
                                    Last post
                                  Buy SketchPlus
                                  Buy SUbD
                                  Buy WrapR
                                  Buy eBook
                                  Buy Modelur
                                  Buy Vertex Tools
                                  Buy SketchCuisine
                                  Buy FormFonts

                                  Advertisement