Issue while loading dll's

Hello, I am trying to load Dll’s from my project but get failed , I have placed my .rb file and .so inside plugin folder of %appdata% and also have another dependency Dll’s when I load .plugin file it invoke another Dll’s which require but I not able to find its own ,for that I need follow any folder structure where i have to store my main .so file and .rb and all dll’s (approx.136)
share me any folder structure or place require to store all dll’s

Thank you in advance

any suggestions?

Switched the category to Developers.

Hello @Anssi I already selected developer category

Your extension files must be in a uniquely named subfolder beneath the %AppData% "Plugins" folder, except for the extension’s registrar script that defines a SketchupExtension data object.

So, the registrar file is the only file that goes in the "Plugins" folder. All other extension files (rb, so, dll, image files, etc.) must go in the extension’s subfolder hierarchy.

Your extension’s registrar script and the subfolder must have the same name.
All your code must be within a unique namespace module and each extension in a submodule of your namespace module.

Let us say that your extension name is “Widget” and your namespace is “ShubHam”.
Then the extension registrar file would be "ShubHam_Widget.rb" and the extension subfolder would be "ShubHam_Widget".

The code module wrapping should follow the file and folder naming …

# encoding: UTF-8
# SketchUp extension registrar file: "ShubHam_Widget.rb"
module ShubHam
  module Widget

    EXTENSION = SketchupExtension.new("Widget", "ShubHam_Widget/loader")

    EXTENSION.instance_eval {
      self.version = "1.0.0"
      self.copyright = "(c) 2023, by author"
      self.creator = "shubhamaher"
      self.description = "A widget for SketchUp."
      Sketchup.register_extension(self, true)
    }

  end
end

From files within your extension sibfolder … you can get the folder path using Ruby’s global __dir__() method.

# encoding: UTF-8
# SketchUp extension loader file: "ShubHam_Widget/loader.rb"
module ShubHam
  module Widget

    require File.join( __dir__, "widget_lib.so" )

  end
end

But be aware that for so, dll, dylib files loaded with Ruby’s require they must have a proper entry point function defined.

// "widget_lib.cpp"

// C++ functions ...

extern "C" {

    // Ruby entry point function always begins with "Init_", ends with file name:
    void Init_widget_lib() {
        // Define ruby interface here which call C++ functions above ...
    }

}

For more information, read the book on extending Ruby with C.

1 Like

You will need to provide complete absolute paths to DLL lib files, and use the Fiddle library.

module Fiddle - fiddle: Ruby Standard Library Documentation