Creating Universal Binary Mach-O plugins for REALbasic

I’ve put together an Xcode template for creating Universal Binary Mach-O plugins for REALbasic. The template will compile a dylib for PPC, and a bundle for Universal Binary – and put these in a plugin folder ready for conversion to a .rbx file.

Updated 3/10/08 for version 1.4 of the template.
Updated 8/1/07 for version 1.3 of the template.
Updated 26/8/06 for version 1.2 of the template.
Updated 23/8/06 for version 1.1 of the template.

To use this template, start by downloading my template files (.zip format, 27KB), and unzip the downloaded template files archive.

Then, do the following:

  1. Make sure you have Xcode installed. You can download it for free from Apple by signing up for a free Apple Developer Connection Online membership. This template has been tested with Xcode 3.1.1.  When you install Xcode, be sure to install the “Mac OS X 10.3.9 package” (it isn’t selected by default), or the plugin template won’t work.
  2. Make sure you are using REALbasic 2006r4 or later for Mac OS X. 2006r4 was the first version to support Universal Binary builds, and so you’ll need this version or later to test your Universal Binary plugin.
  3. Make sure you use the latest REALbasic Plugin SDK (included in the REALbasic download for Mac OS X, in the “/Extras/Plugins SDK/” folder).
  4. Copy the folder “REALbasic”, from the downloaded template files, to “/Developer/Library/Xcode/Project Templates/” (which is where Xcode keeps its project templates).
  5. Launch Xcode.
  6. Select “File > New Project…”.
  7. Select the REALbasic category under the Mac OS X category, and then select the “REALbasic Universal Binary Mach-O Plugin”.  Click “Choose…” to use this template.
  8. Give the project a name. This will also be the name of your plugin, and the folder the project lives in. By default the new folder will be created in your home folder, but you can change this to another location.
  9. Click “Finish”. A new project will open, and a new project folder will be created on your hard disk, wherever you chose above.
  10. Find this folder on your hard disk, and copy the “Glue Code” and “Includes” folders from the latest Plugins SDK into the root level of your new project’s folder. Switch back to Xcode, and you should see that the “Glue Code” and “Includes” folders and files in the Xcode file list have turned from red text to black text.
  11. By default, the plugin contains one global method, called CurrentArchitecture. You can now compile your plugin, and give this method a test! Just select “Build > Build” in Xcode (or press Apple-B), and both the PPC and Universal Binary dylibs will be built.
  12. The first time you build the project, you will get four warnings that build folders do not exist. Ignore these warnings – they’re just caused by Xcode creating the folder structure for your plugin.
  13. Once you have built the empty plugin, you’ll find that a new folder will have be created by Xcode in your project folder. It will have the same name as the project. This folder is the skeleton structure of your plugin. It will contain one folder, called “Build Resources”. “Build Resources” will contain two folders: “Mac Carbon Mach-O”, containing the PPC dylib, and “Mac Carbon Mach-O Universal”, containing the Universal Binary bundle.
  14. To make these two files into a plugin (also known as a .rbx file), you’ll need to use the “Plugin Converter” from the REALbasic Plugins SDK. Open the “Plugin converter.rb” project, and build the project. This will build an application called “RB Plugin Converter”.
  15. Run this application, and click on the “Convert Folder” button. Find your project folder, and select the subfolder with the same name (you’re selecting the folder that contains the “Build Resources” folder). Click on “Choose”.
  16. The Plugin Converter will prompt you to select where you want to save the built plugin. Select your REALbasic Plugins folder (something like “/Applications/REALbasic 2008r4/Plugins/”, and click “Save”. A file called “YourProjectName.rbx” will be created in the Plugins folder. This is your plugin!
  17. Your plugin is now ready to go. Launch REALbasic, open the sample project included with the template download – “PluginTest.rbp” – and build the project. It will build as a Universal Binary application called “PluginTest.app”. If you run “PluginTest.app” on a PowerPC Mac, it will use the CurrentArchitecture global method to display a message saying that it is running the PowerPC code. The same goes for if you run the app under Rosetta on an Intel Mac. If you run “PluginTest.app” natively on an Intel Mac, then it will say it is running the Intel plugin code.
  18. Once you have finished developing and testing your plugin, switch Xcode to use the “Deployment” build configuration. You can do this from Xcode’s “Project > Set Active Build Configuration” menu. Build the plugin again. The Deployment build configuration strips out any unused code and symbols, and results in a much smaller plugin file. Use this version of the plugin in any applications you distribute.

Version 1.4, 3/10/08

Updated the instructions for REALbasic 2008r4 and Xcode 3.1.1.

Version 1.3, 8/1/07

Changed the Universal Binary part of the plugin to be a bundle rather than a dynamic library.  This will take advantage of a new feature in future versions of REALbasic, where the Universal Binary part of the plugin will be loaded directly into memory and not written out to disk.

Changed the target order to ensure that “Build All” is the default.

Version 1.2, 26/8/06

Added in an exports file to the Deployment build configuration for both PPC and UB, and set this build configuration to use Dead Code Stripping.  This reduces the size of the built Deployment plugin considerably.

Changed the SDKs and Mac OS X Deployment Targets to build for 10.3.9 with GCC 3.3 for the PPC target and the PPC part of the UB target; and to build for 10.4u with GCC 4.0 for the i386 part of the UB target.  This means that 10.3 can be supported for backwards compatability.

Disabled Prebinding for the i386 part of the UB target, as it is 10.4 only and therefore doesn’t need prebinding.

Removed the unused “Default” build configuration.

Version 1.1, 23/8/06

The PowerPC dylib is now built as a PowerPC target when compiled on an Intel machine.  Previously it was being compiled as $(NATIVE_ARCH), which would build as PPC on PPC, and Intel on Intel.  Thanks to Philippe Rigaux for spotting this error.

The UB dylib now compiles against the 10.4u SDK, at /Developer/SDKs/MacOSX10.4u.sdk/.  This means that it will actually compile :-)

A sample global method, CurrentArchitecture, is now included in the plugin template.

A few other compile settings have been moved from being Target settings to being Project settings, to avoid duplication.

Version 1.0, 21/8/06

Initial release.

24 thoughts on “Creating Universal Binary Mach-O plugins for REALbasic

  1. Thanks for the help! Everything went smoothly for me, except that building the plugin only creates a “Mac Carbon Mach-O” folder, not a Universal version. If you know why this might be, could you let me know?

    Thanks again.

  2. Thanks a lot! Got the example working having no previous XCode experience. Now if I only could manage to prepare my own plugins…

  3. HOLY CRAP THIS ROCKS!!!!! I had to create the non-universal binary version of my plugin a while back by following RB’s instructions. It took WEEKS!! I used this walkthrough for the new UB version. It simplified it down to very clear specific steps taking minutes. THANK YOU! THANK YOU! THANK YOU!!!!!!!!

  4. One gotcha: The initial project had the target set to just the PPC build. Had to change the target to ‘Build All’ before it would build the Universal AND PPC. Rather than that, instructions were extremely detailed.

  5. Pingback: Home of Echelon » SDL_mixer plugin for REALbasic 2006

  6. Pingback: BLAB » Blog Archive » Middle Aged Game Developers

  7. I’ve just tried your XCode template for a new plugin project: it’s working quite nicely.
    I’ve got only one minor issue – the plugin converter project file extension should not be .rb but .rbp – don’t ask me why but here the .rb is not launching RB but BBEdit (I am using RB 2007.2).Very well done anyway – thank you very much.

  8. I have tried to build my first plugin, but it crashes in the Glue Code. Any idea what might have gone wrong?

    Thanks

    Alex

  9. Built the Plugin in mintues.. Nice and Easy.
    However now what?
    Looking at my RB IDE I don’t see a new control in the project… What Control did this PluginTest.rbp use?
    I mean the Window1 Open routine simply Looks at a Variable Called CurrentArchitecture…
    I see this in myplugin.cpp and I think I grok it but, shouldn’t there be a control or something refrencing this plugin in RB somewhere?

  10. Type your comment here.
    PluginTest.rbp wouldn’t run under OSX.
    The line of code I’ve marked X was the problem.
    X if CurrentArchitecture = 0 then
    MsgBox “Running PPC code from plugin”
    else
    MsgBox “Running Intel code from plugin”
    end if

    Up to that point, everything was very smooth & extremely well articulated. Many thanks for making this available.
    Walt Gibbs

  11. Hi Tim,

    Good idea. TBH, most of my RB development is Mac-only, so as yet I haven’t had the need myself to do so. So maybe I’ll expand it one day, but not right now :)

    Dave.

  12. Thanks a lot ! I tried druring one month to make a plug-in from XCode… And now it works ! Npalardy gave me your link on the realbasic forum. I am a newbie with C++. Could give an example (in C++) of a routine with a double loop like :
    for i=0 to XCompt
    for j=0 to Y Compt
    next
    next

    I’d like to work with pictures from Realbasic. I would like to write a subroutine like
    TransformPicture(Src as picture,param1 as interg…) as picture.

    Is there someone to help me ?

    Thanks in advance.

    Géraud

  13. Has anyone managed to get this to work with XCode 3.0 under Leopard?? When I try to build the project it throws a wobbly saying it can’t find the SDK or GCC 3.0! I changed the build settings to use the 10.4u SDK as Leopard doesn’t seem to come with the 10.3u SDK and also changed the GCC version to 4.0 which seemed to let the project build with only the usual deprecated warnings. But when I load RealBasic is doesn’t seem to have loaded the plugin.

  14. Hi Milly,

    If you’re using the latest version of XCode (3.1.1 at the time of writing), you’ll need to make sure that you also install the “Mac OS X 10.3.9 Support” package during the XCode installation. Otherwise any REALbasic plugins created from my template won’t compile without changing some settings.

  15. Now that I’ve built my first universal plugin, actually my first plugin how do I reduce its size?
    What can I strip out in the MainPlugin, does anybody have any samples?

  16. Hi Steve,

    You should find that the plugin is much much smaller when you build the plugin with the Deployment configuration. Everything unnecessary is stripped out for this configuration. So, you’d develop and test with the Development configuration, and then when everything is working, switch to the Deployment configuration, build, and use that one instead.

    Dave.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>