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

C++ using swig

Scheduled Pinned Locked Moved Developers' Forum
18 Posts 5 Posters 1.6k 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.
  • B Offline
    brewsky
    last edited by 19 Jan 2015, 20:47

    Hi Everyone,

    I've been trying to connect to a C++ library from SU(windows) using swig.
    No success so far... Not even the most basic examples.
    I'm rather new to C++, but compiling swig using python works ok, ruby ?!? no way...

    Is there anyone that has used swig on a recent(ruby2.x) sketchup version on windows?
    I would love to have some tips on this.

    Some problems I ran into:

    • ruby does not seem to provide MSVS builds anymore, only MingW. It seems to me that the ruby build in SU is also done using MinGW, is that correct?
    • swig examples are ancient and point to these old MSVS builds, it also seems that(for swig) MSVS would be preferable over MinGW.(I didn't have much trouble compiling swig/ruby on linux.)

    I thought it better to ask a general question to see if anyone has been using swig+sketchUp recently before I start "spewing" out build errors πŸ˜‰ might be that a swig or C++ forum would be a better place for this question...

    Thanks!
    Jan

    Sketchup BIM-Tools - http://sketchucation.com/forums/viewtopic.php?p=299107

    1 Reply Last reply Reply Quote 0
    • J Offline
      jolran
      last edited by 19 Jan 2015, 22:59

      Havent tried swig.

      Are you using the provided examples at the Github Project ? They should be relatively new.
      https://github.com/SketchUp/ruby-c-extension-examples

      If you follow this "not so old" discussion there some info about C++ extensions.
      Not swig releated, but you might change idea and go straight C++.
      (Can't see why it woulden't be more straightforward using C++ for connecting to a C++ library.)
      http://sketchucation.com/forums/viewtopic.php?f=180%26amp;t=58825

      As you can see I'm not expert at the subject. But picking up the example I could just hack away. It worked pretty much straight of the bat. Well almost πŸ˜‰

      Thomthom might provide you some more solid advice about the subject..

      1 Reply Last reply Reply Quote 0
      • T Offline
        tt_su
        last edited by 20 Jan 2015, 10:10

        I'm not familiar with SWIG I'm afraid. Bugra set up the SWIG example - I can ping him if it needs be.

        1 Reply Last reply Reply Quote 0
        • B Offline
          brewsky
          last edited by 20 Jan 2015, 19:10

          Hey Guys, this looks great! πŸ˜„ Too bad that I didn't notice this project before... It even seems to be Swig based! I'll dive right into it πŸ˜„

          @jolran said:

          Are you using the provided examples at the Github Project ? They should be relatively new.
          https://github.com/SketchUp/ruby-c-extension-examples

          I have been trying the examples from the swig website but these are really old.

          Thanks!

          Sketchup BIM-Tools - http://sketchucation.com/forums/viewtopic.php?p=299107

          1 Reply Last reply Reply Quote 0
          • J Offline
            jolran
            last edited by 20 Jan 2015, 19:21

            πŸ‘ Good luck!

            1 Reply Last reply Reply Quote 0
            • G Offline
              Garry K
              last edited by 17 Feb 2015, 15:20

              I'm a C++ programmer from way back however I haven't worked with Visual Studio for many years.

              I've just installed Visual Studio 2010 Express and installed the examples.
              I've also downloaded the SDK. Where should the SDK go?

              Additionally I am experiencing a link error when trying to build SUEX_HelloWorld and SUEX_UsingSWIG
              I'm guessing that the compiler can't find the SDK.

              I see that slapi.dll started shipping with SU8 to now.
              I'm thinking there should be a slapi.lib file.

              1 Reply Last reply Reply Quote 0
              • G Offline
                Garry K
                last edited by 17 Feb 2015, 17:10

                I've got it compiling - how do I get it to actually run.

                1 Reply Last reply Reply Quote 0
                • T Offline
                  tt_su
                  last edited by 18 Feb 2015, 17:37

                  @garry k said:

                  Additionally I am experiencing a link error when trying to build SUEX_HelloWorld and SUEX_UsingSWIG
                  I'm guessing that the compiler can't find the SDK.

                  You don't need SWIG to make a Ruby C/C++ Extensions. If you just want to use the C API licensing features you just need the basics of what SUEX_HelloWorld demonstrate and then add the C API headers and libs to the project.

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    jolran
                    last edited by 18 Feb 2015, 22:04

                    Like Thomthom said.

                    If you look at this topic (same as link above) there is a lot of information for setting up things.

                    TT guides me through the ordeal in a usual friendly way. πŸ˜„

                    http://sketchucation.com/forums/viewtopic.php?f=180%26amp;t=58825

                    Also (to my liking) switching to a newer Visual Studio gave better compability with C++ 11
                    making it easier to work with vectors for ex. I highly recommend doing that.

                    1 Reply Last reply Reply Quote 0
                    • G Offline
                      Garry K
                      last edited by 19 Feb 2015, 14:42

                      I fixed the link error and have SUEX_HelloWorld working.
                      I also have WritingToAskpFile working.

                      skp_to_xml and xml_to_skp do not compile. They require afx.h and afxole.h which did not ship with Visual C++ 2010 express.

                      I haven't tried licensed_ruby_extension nor TextureMapping

                      Jolran - thanks for the tip about the compiler and I will read your link. I'm going to need to play with the XCode compiler as well. So far I haven't found out what the costs will be.

                      There is a visual studio 2012 express but I don't see a link from microsoft for visual c++ 2011 express.

                      1 Reply Last reply Reply Quote 0
                      • thomthomT Offline
                        thomthom
                        last edited by 19 Feb 2015, 15:31

                        Don't think there was a C++ 2011. There was 2010 and 2013.

                        Garry, was the skp_to_xml example set up to AFX? Don't think it would need that. Lemme look that up when I get into the office.

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

                        1 Reply Last reply Reply Quote 0
                        • G Offline
                          Garry K
                          last edited by 19 Feb 2015, 17:43

                          The stdafx.h file contains

                          #include <SDKDDKVer.h>
                          #include <afx.h>
                          #include <afxole.h>

                          1 Reply Last reply Reply Quote 0
                          • thomthomT Offline
                            thomthom
                            last edited by 19 Feb 2015, 20:36

                            So, I asked how that example was made, and it uses MFC for the option dialogs, meaning you cannot use the Express edition to compile it.

                            The Visual Studio 2013 Community edition would let you compile if you upgraded the project - but then it would not run inside of SketchUp because of runtime clashes.
                            http://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx

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

                            1 Reply Last reply Reply Quote 0
                            • G Offline
                              Garry K
                              last edited by 19 Feb 2015, 21:41

                              I've got an XE4 C++ compiler working with slapi.dll for windows X86 but so far only with WritingToAskpFile source code.

                              The key bit was to create an XE4 compatible lib file by running implib.exe with the correct calling convention. Implib.exe comes packaged with XE4.

                              implib.exe -a slapi.lib slapi.dll
                              The -a is for cdecl calling convention which is MS default
                              I will try with the X64 and see what it takes for Mac OSX versions

                              There are a number of advantages at least for me to use XE4

                              1. The XE4 compiler compiles windows 32 + 64 bit and OSX
                              2. There shouldn't be runtime clashes because XE4 uses different libraries
                              3. I have years of borland c and c++ source code
                              4. Hopefully no need to have xcode compiler

                              I know this is still very preliminary - but I am excited by the possibilities

                              1 Reply Last reply Reply Quote 0
                              • G Offline
                                Garry K
                                last edited by 19 Feb 2015, 21:56

                                I also have it compiling win32 code in C++Builder 6 - but I did use the XE4 implib.exe

                                Instead of using all runtime libraries you can compile a self contained exe - quite a bit larger. Then all you need is borlands memory manager as a runtime.

                                1 Reply Last reply Reply Quote 0
                                • thomthomT Offline
                                  thomthom
                                  last edited by 19 Feb 2015, 23:10

                                  I'm currently building my Visual Studio builds with /MT instead of /MD - to prevent the need to install the crts - since I build with VS2013's dev chain instead of the 2010 which SU currently use.

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

                                  1 Reply Last reply Reply Quote 0
                                  • G Offline
                                    Garry K
                                    last edited by 19 Feb 2015, 23:51

                                    I'm just currently playing around to see how far I can take this. Even though I'm licensed with XE4 I prefer the ease of use of C++Builder 6.

                                    I can successfully import libraries from SU8, SU2013, SU2014 and SU2015
                                    The sample code to write an skp file works with SU2013, SU2014 and SU2015 but not SU8

                                    It appears the library is significantly smaller for SU8, therefore there must be a lot missing.
                                    I'm thinking that it might be time to drop SU7 and SU8

                                    I can remove lots of libraries from CBuilder by simply unchecking things. I can also build microsoft compatible DLL's if needed (change the calling convention)

                                    I've only been playing around with interfacing with SU for the last 3 days. I should have a handle on it by early next week.

                                    Now for Swig and C++Builder 6

                                    1 Reply Last reply Reply Quote 0
                                    • thomthomT Offline
                                      thomthom
                                      last edited by 20 Feb 2015, 00:19

                                      For my own extensions that I write now I usually drop support for anything older than SU2014 - due to Ruby 2.0 and other improvements since then.

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

                                      1 Reply Last reply Reply Quote 0
                                      • 1 / 1
                                      • First post
                                        Last post
                                      Buy SketchPlus
                                      Buy SUbD
                                      Buy WrapR
                                      Buy eBook
                                      Buy Modelur
                                      Buy Vertex Tools
                                      Buy SketchCuisine
                                      Buy FormFonts

                                      Advertisement