Giter Club home page Giter Club logo

ruby-c-extension-examples's Introduction

SketchUp Ruby C/C++ Extension Examples

This project includes the Ruby lib and header files used by SketchUp.

C++ Example - Hello World

Visual Studio 2022

(For older Visual Studio versions, check out the various git tags.)

Notes on how the solution is set up:

  • The project name must match the name of the Init_*() function. Example: If the project name is HelloWorld the init function must be named Init_HelloWorld.
  • The init function must be exported in the .def file - named the same as the project.

Debugging

The Visual Studio project is set up to launch SketchUp and then load the built Ruby C Extension so you can debug your code. The various build configuration is set up to launch different SketchUp versions. Refer to the project configuration and make your adjustments as needed:

SUEX_HelloWorld > Right Click > Configuration Properties > Debugging

Xcode 14

Xcode project is set up to build targets all the way back to Ruby 2.0.

Windows and Runtime DLLs

SketchUp itself builds Ruby with dynamic CRT - using the /MD flag.

SU2014 - SU2016 used VS2010 runtime. The SketchUp installer will install the required runtime on the user machine if needed. This mean that if you build your extension with /MD with the same CRT you don't have to worry about this.

However, if you built with another CRT you have to ensure yourself that it's installed on the user's machine - which isn't trivial for a Ruby extension unless you bundle an installer with it.

This then poses a challenge when you want to support SU2017 which uses VS2015 runtime and also older versions that uses VS2010 runtimes. Either you need to build your C extensions with different VS compiler versions, or you need to ensure yourself the runtimes are on the user machine.

The runtimes libraries will usually be on a user machine, but you might experience some users with brand new machines or when a runtime is brand new that some doesn't.

Incidentally we have upgraded the Ruby version at the same time as we upgraded the compiler version. But that's just by chance.

Because of this you might want to build your extensions with /MT. However, the Ruby config files are not set up for that by default. Hence the need to define from extra macros as seen the TestUp project. This is because there are some differences between /MD and /MT that would otherwise create compile errors.

Statically linking the CRT in my C extensions means they will be bigger, but you don't have to worry about the user not having the required DLLs.

ruby-c-extension-examples's People

Contributors

bugrabarin avatar eneroth3 avatar olilej avatar tdapper avatar thomthom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ruby-c-extension-examples's Issues

Newbie problem - creating corresponding rbz?

Hi,
I'm trying to get this HelloWorld project for SketchUp running with win7 with VS 2015 and SU2016 - I t I do it would try it without "SWING"
without success...
I'm missing the ruby code or extension; that would run .so file, and did not manage to make it based on the SketchUp extension su_create_layout_file...

the same problem the other way around:
**I've written a C program which runs good as an exe, and would like to create a Sketchup Extension from it... I've tried to start with the github HelloWorld project, but did not manage to create the appropriate rb file to get it work... I recieve an error message:

Error: 193: %1 ist keine zulässige Win32-Anwendung. - path of .so file
which means "is no valid" Win-32 application....

what did I do wrong?**

Could you give me any clue please...
Thanks in advance!

see also:
https://forums.sketchup.com/t/problem-on-c-ruby-extension/31386/3

Build failed for Release (2.0) x64 platform

Using VS Express 2015 for Windows Desktop.

I had to change the Runtime Library to use the /MD option instead of the /MT option in order to build SUEXT_HelloWorld for Release (2.0) on the x64 Platform.

Properties > C/C++ > Code Generation >Runtime Library

2016-09-10_130113

Does this project still work in SUP2021?

I use VS2019 build the 'HelloWorld' project and require .so file in ruby console by one line code:

require 'F:/Data/ruby-c-extension-examples-main/Release (2.2)/x64/SUEX_HelloWorld.so'

But I get an error:

Error: #<LoadError: 126: \x{D5D2}\x{B2BB}\x{B5BD}\x{D6B8}\x{B6A8}\x{B5C4}\x{C4A3}\x{BFE9}\x{A1A3}   - F:/Data/ruby-c-extension-examples-main/Release (2.2)/x64/SUEX_HelloWorld.so>
E:/SketchUp/Tools/RubyStdLib/rubygems/core_ext/kernel_require.rb:92:in `require'
E:/SketchUp/Tools/RubyStdLib/rubygems/core_ext/kernel_require.rb:92:in `require'
<main>:in `<main>'
SketchUp:in `eval'

My friend use the same way to build it and work well.His SUP version is 2018,so I wonder if this project is still valid in SUP2021.

use SDK_Mac_17-0-18898 and ruby-c-extension-examples BUG

incompatible library version - SUEX_HelloWorld_2017/SUEX_HelloWorld.bundle

Xcode Version 8.2.1 (8C1002)
ruby-c-extension-examples master
SDK_Mac_17-0-18898

add SketchUpAPI.framework to project , build 。 sketch 2017 pro ruby console,require 。

got “incompatible library version ” error

ruby 2.0 32 bit win compilation fails due to compiler requirement in config.h

For the 64 bit versions, you modified the config.h file from the Ruby includes by commenting out the requirement for a specific compiler version by commenting out this:

#if _MSC_VER != 1600
#error MSC version unmatch: _MSC_VER: 1600 is expected.
#endif

The 32 bit include still has this and compilation with Visual Studio 2015 therefore fails.

Linking errors when building bundles on Xcode

I checked out dev/arm64 and tried to build the project and got this error

ld: warning: ignoring file /Users/dalemartens/mind.sight.studios Dropbox/Dale Martens/Plugins/ruby-c-extension-examples/ThirdParty/lib/mac/2.7-universal/Ruby.framework/Ruby, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x56 0x65 0x72 0x73 0x69 0x6F 0x6E 0x73 0x2F 0x43 0x75 0x72 0x72 0x65 0x6E 0x74 )

Running MacOS 12.1 and Xcode 13.2.1 on an M1 Mac mini

SUEX_UsingSWIG - Include directory points to Ruby 2.0 instead of 2.2 in Release (2.2) x64 / Win32

I noticed that the include directory for Release/Debug (2.2) win32 and x64 point to 2.0 Ruby folder . Should it be pointing to 2.2 folder instead?

Also I am receiving the following error in VS2015 with when compiling using /MT in Release (2.2) x64:
c:\ruby-c-extension-examples\thirdparty\include\ruby\2.2\win32_x64\ruby/missing.h(76): error C2375: 'acosh': redefinition; different linkage

C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\math.h(477): note: see declaration of 'acosh'

Within this configuration for Release 2.2 in Linker > Input > Dependencies it links x64-msvcrt-ruby200.lib instead of x64-msvcrt-ruby220.lib. Is it possible that the 220 lib has been compiled with /MD instead of /MT?

Thanks,
Anthony

Ruby file names...

The naming x64-msvcrt-rubyMm0 (major, minor) has been around for quite a while, and was based on publicly available Ruby builds.

Ruby 3.1 is now publicly available only as an MSYS2 ucrt64 build, with file names x64-ucrt-ruby310. Current Ruby mswin builds are named x64-vcruntime140-ruby310.

So, is it time to name the Ruby files to match stand-alone Ruby builds, and use the mswin name?

Some background:

Recently in the SU forum there was thread mentioning issues with extension gems. I believe they were building with a mingw Ruby 2.7.

I thought I'd see if I could repo it, and started with stand-alone master builds (I built a custom mswin with ucrt naming). After a bit of work, I noticed that the functions in x64-vcruntime140-ruby310.dll do not match the functions in x64-ucrt-ruby310.dll. So, even though Ruby mswin & ucrt builds use the same runtime, they are not the same.

Off-topic:

Ruby 3.1 will build with VS 2022, but it fails some numeric tests. It does build with VS 2019. The bug in 2022 is fixed, but hasn't been released. If you want more info, I can look things up. Ruby master is currently patching around the bug, but since it's assumed it will be fixed/released, the changes haven't been backported...

The Ruby mswin builds used for CI are using Microsoft/vcpkg for libffi, libyaml, openssl, readline, and zlib. Note that the current package OpenSSL version is 'OpenSSL 3.0.5 5 Jul 2022'.

Finally, a stand-alone mswin version of 3.1.2 is available as a release asset in MSP-Greg/ruby-mswin. For several years I have maintained ruby-loco, which has mingw, ucrt, and mswin builds of Ruby master/head. I decided to create ruby-mswin to buld/test/save mswin Ruby release builds, since they aren't available anywhere. RubyInstaller2 only has mingw (ruby 2.4 thru 3.0) and ucrt (Ruby 3.1 and later).

Can GetRubyInterface() be aliased?

QUESTION (C function aliasing)

REF: "src/RubyUtils/RubyUtils.h"

Can GetRubyInterface() be aliased? It is quite a long function name (16 chars) and will serve to make code noisier.

How about something shorter that indicates a conversion to VALUE ?
Ideas in order of preference:

  • VAL()
  • val()
  • value()
  • C2VAL()

Add some examples with substance.

The Hello World is a silly and meaningless example.

Add some examples with substance. Something that at least looks up some SketchUp model properties and displays them.

Extension which uses Z depth/Z channel

Hi,

The contact part of the developer site was giving me a 404 and I can't find anything on the docs nor in the examples in this repo to provide an answer to this.

I want to create an extension which uses the (inverted) z depth/z channel of the user's sketchup model. This tweet was my inspiration:

https://twitter.com/hardmaru/status/1601513412575793155

I'm wondering how I can extract this data in SketchUp? If you could give me any pointers I would be very grateful.

Thank you in advance!

The Sketchup&&LayOut 2017 SDK BUG

Hi:
I download the 2017 SketchupAPI SDK and LayOutAPI SDK, I use RubyExampleCreateLayOut sample,but create .so file can't work on Sketchup2017. But I use MacOS, the same project work well.

I test the code:
this code not work,if I use LOInitialize;

 VALUE create_layout_doc(VALUE self, VALUE skp_path) {
      LOInitialize();
      return Qtrue;
}

But this code not work:

 VALUE create_layout_doc(VALUE self, VALUE skp_path) {
      return Qtrue;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.