Using gcc to compile a VST plugin on OS X

It’s been so long since I’ve posted any code… It’s actually been so long, I’m pretty sure the code I’ve posted got dropped a couple of blog migrations ago.

I don’t have anything against all the fancy tools like Visual Studio, XCode and Eclipse… well, except that they have huge footprints and hide a lot of the work so that you really don’t know what’s going on behind the scenes. I was pretty frustrated reading through various tutorials and message boards where, when asked, most of the people shrugged off the idea of using gcc to build VST plugins.

Sure, you wouldn’t want to do it day in and day out, but if you want to, for instance, use maven or Eclipse’s CDT rather than XCode or Visual Studio, you need to know what’s going on under the covers – to break it down to it’s components and build from there.

I managed to get the ‘again’ plugin compiled from the command line with a minimum of fuss and will most likely continue working this way until I can get Eclipse CDT configured properly.

Here’s a set of commands that will get you going.
First is the easy part. Build the assembled binaries of your plugin and the VST library.

gcc -x c++ -arch i386 -mmacosx-version-min=10.4 -I ../../includes/vstsdk2.4 -c -o obj/audioeffect.o
gcc -x c++ -arch i386 -mmacosx-version-min=10.4 -I ../../includes/vstsdk2.4 -c -o obj/audioeffectx.o
gcc -x c++ -arch i386 -mmacosx-version-min=10.4 -I ../../includes/vstsdk2.4 -c -o obj/vstplugmain.o
gcc -x c++ -arch i386 -mmacosx-version-min=10.4 -I ../../includes/vstsdk2.4 -c -o obj/again.o src/ag

Then create a placeholder for what will become the plugin package and link the object files into a bundle.

set MACOSX_DEPLOYMENT_TARGET 10.4
mkdir -p bin/again.vst/Contents/MacOS
g++ -arch i386 -bundle -mmacosx-version-min=10.4 -o bin/again.vst/Contents/MacOS/again obj/again.o o

The next step will create an OS X package that will be treated as a VST plugin. I placed the Info.plist and PkgInfo files into the resources folder and copy them over at the end.

cp -r src/resources/* bin/again.vst/Contents/

The Info.plist file looks like this for the ‘again’ example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleDevelopmentRegion</key>
	<string>English</string>
	<key>CFBundleExecutable</key>
	<string>again</string>
	<key>CFBundleIdentifier</key>
	<string>de.steinberg.vst2.4.example.again</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>again</string>
	<key>CFBundlePackageType</key>
	<string>BNDL</string>
	<key>CFBundleShortVersionString</key>
	<string>1.0</string>
	<key>CFBundleSignature</key>
	<string>????</string>
	<key>CFBundleVersion</key>
	<string>1.0</string>
	<key>CSResourcesFileMapped</key>
	<true/>
</dict>
</plist>

And the PkgInfo file is a single line that looks like:

BNDL????

Next, I’m going to try to get this working with a cross compiler so that I don’t have to run one script on OS X and another on Windows. We’ll see how that goes. Hopefully both should work with my VST-RTAS wrapper in Pro Tools… keeping my fingers crossed.

Leave a Reply