Cannot load OSX Ruby C Extension

I’ve been using the OSX sample as a guide, along with the Xcode settings. I’m pretty sure I’m overlooking something though.

Right now, I have a target SDK of OSX 10.9, with an export definitions that follows suite with the one given in the example. So, the layout looks like this:

header

#define EXPORT_DEF __attribute__((visibility("default")))

extern "C" EXPORT_DEF Init_my_project_name( void );

source

extern "C" {
EXPORT_DEF void Init_my_project_name( void )
{
      // do stuff  
} 
}

my_project_name_exports.txt

_Init_my_project_name

The exports file is listed under the setting “Exported Symbols File”, as was the case with the example, so I know that can’t be it.

I’m also compiling the library via the Bundle project template, using mostly default settings (anything which isn’t default was changed to match the project settings within the example). The Ruby 2.0 framework is also linked to the bundle.

Any insight? I’ve also tried requiring .dylib files within Ruby, but no dice.

I’ve successfully set this up in Windows; I’m just new to the whole OSX way of things.

hmm… I think I did the same thing first time and also found it to fail. I think I had to use Library instead:

I had to change the project config to have .bundle extension. I’m not sure why, I think this might be a Ruby naming convention. (On Windows the files are named .so but they are in reality .dll files.)

I’m not on my Mac right now, but have a look at our Ruby C++ Example on GitHub and compare what config and project it’s set up with.

@bugra - are you able to clarify this?

1 Like

That’s right, you do not want to do a “Bundle” since that’s quite different. I would start with the Library template and change the “Mach-O Type” to Bundle. Then change “Executable Extension” to bundle and get rid of the “Executable Prefix”, which defaults to lib. Also make sure to set the “Exported Symbols File” to your exports file name. After building, you can check if the Init function was made public by this command:

nm -g <built_library_path> | grep Init

2 Likes

Hmm… I had left that to the default “Dynamic Library” for my last project. Still worked in SketchUp. What is the difference here? This isn’t the property that the project templates would be setting?

Just checked out GitHub examples, they are also set to “Mach-O Dynamic Library”.

Yeah dylibs would work too. AFAIK, there are just subtle differences in dynamic loading behavior.

Righteous - tips worked great. Thanks, guys.