C extensions for Mac and Windows and RBE versions of sketchup

I’m interested in determining the lowest common denominator for creating c/c++ extension for Sketchup.

Windows first:
Can I use VS 2015 and properly create extensions for SU 2016, 2017 and 2018? I would like to compile it without the need of additional external libraries. So I would be linking at compile time (a bit larger - but hopefully simpler). I’m guessing that I should create a 32 bit and a 64 bit version for SU 2016. I would need another version for SU 2017. Question is will that also work for 2018 or do I need to build a different version? I have lots of experience with C/C++ but have gone down the Borland / Embarcadero path. I have used Microsoft CE compilers but that goes back a lot of years.

Mac OSX
Which xcode compiler would I need to support the Mac versions of SU 2016, 2017 and 2018. I’m guessing that I would need to provide 3 compiled versions since SU has dropped older OS support for each of these releases. I have no experience with xcode compiler. Also - I do not have any Mac devices. Is there a way to compile the code without having to have a device and not having to register with Apple (I don’t want to get involved with the Apple store)

has a cross compiler for mac and so does VS 2015 according to the web …

with Xcode:

I have compiled C/C++, ObjC, Swift as ‘Command Line Tool’ bin scripts for use is SU, and call them using Ruby’s #system variants…

Similar method to this link

I have also compiled the Ruby C extension samples as ‘.plugin’ files, but they are harder to include in an extension…

@jiminybillybob may have some insight, I think he uses Xcode on a HacIntosh…

john

Did someone try cross-compiling? (Isn’t that for exactly that purpose, so SketchUp should make developers lifes easier and support it.)

A couple of years ago I spent 2 months porting code over to FireMonkey (Embarcadero’s cross compiler). First of all there were so many bugs. Secondly to support both OS’s I would have had to purchase additional libraries. Additionally to support barcoding I would have had to purchase additional libraries. Finally I would have had to purchase a Mac device. Suffice it to say that I gave up and went back to VCL. That was on XE8. I’m sure that their latest version is better - but an upgrade is still over 900$ US and I would still have to do a lot of rewriting.

If Trimble went to a cross compiler they would most likely have to rewrite all their visual libraries. I suspect that won’t happen any time soon.

You can refer to GitHub - SketchUp/ruby-c-extension-examples: Ruby C extension examples. It comes with an example project, configured for both Windows’s Visual Studio and Mac OS X’s xCode. For Windows, you can use whichever VS studio you want. I personally use VisualStudio 2017 community, and compile it with compatibility for windows XP. For Mac OS X, you can use xCode.

When compiling, you will get .so files on Windows and .bundle on Max OS X. You can load them using the standard Kernel require function. For windows, you would want your c extension compiled for win32-2.0, win64-2.0, win64-2.2, and win32-1.8 (if want compatibility with SU version prior to 2014). win64-2.2 also works with SU2018, since SU2018 uses Ruby2.2, just like SU2017. Same applies to osx, but you can also configure it to compile for osx32 and osx64 merged into one.

Also, you won’t need to have any external libraries when shipping your extension (unless you specifically indicate or disable the MT flag).

When you load your extension, you will have to load it based on the platform, Ruby version, and whether Sketchup is 32/64 bit.

Usually you would ship your extension with the following structure:
your_extension/
win32/
1.8/your_lib.so
2.0/your_lib.so
win64/
2.0/your_lib.so
2.2/your_lib.so
osx32/
1.8/your_lib.bundle
2.0/your_lib.bundle
osx64/
2.0/your_lib.bundle
2.2/your_lib.bundle
ruby_files…

RBE files are encrypted version of ruby files, that can be interpreted by SketchUp, specifically SU2016 and later. You can apply encryption to your ruby files when using the extension signature tool.

To load an rbe/rbs file, you will have to use Sketchup’s require function: Sketchup.require ‘some_ruby_file’. Adding an extension isn’t necessary. Generally, you would want to load .bundle/.so using Kernel.require and any type of ruby file, using Sketchup.require.

3 Likes

When I made the statement. RBE I had hoped that readers would get the idea that I am only interested in SU 2016, 2017 and 2018.

I was under the impression that Mac versions for SU 2016, 2017 and 2018 were all 64 bit. So I’m thinking that I need: (or am I missing something)?

my_extension/
win32/
2.0/your_lib.so
win64/
2.0/your_lib.so
2.2/your_lib.so
osx64/
2.0/your_lib.bundle
2.2/your_lib.bundle

That’s correct - for Mac OS X SU2016 and up you only need the 64bit binaries.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.