Tutorial: Open Source on iOS (Part 4): Compiling libvorbis

This is the forth in a series of posts on building open source libraries for iOS. This tutorial uses the scripts and directory structure developed in the first three posts and applies them to compiling the libvorbis open source audio codec. Please make sure you have completed the previous tutorials before attempting this one.

Obtaining the Source Code

Create a directory for your build (in $IDZ_BUILD_ROOT).

Download and decompress the source

You now need to change the -O4 optimization in the configure script. Open the file libvorbis-1.3.3/configure file and locate the following section:

Change the -O4 to -O3 and remove all the -force_cpusubtype_ALL flags:

You will also need to edit libvorbis-1.3.3/lib/os.h. Locate the following section, near line 84:

And change it to:

This disables a special rounding macro used for the i386 architecture that does not seem to work correctly on the simulator.

Building the Static Libraries

You are now ready to attempt a build.

Lots of messages will print on your terminal, but the last few lines will be:
configure: error: Ogg >= 1.0 required !
make: *** No rule to make target clean'. Stop.
make: *** No targets specified and no makefile found. Stop.
make: *** No rule to make target
install’. Stop.
It would appear that the build is looking for libogg but does not know where to look for it.

To find information about the command line options to a configure script you use the --help argument.
libvorbis-1.3.3/configure –help
The relevant line is
–with-ogg=PFX Prefix where libogg is installed (optional)
The idz_configure script will append the contents of the environment variable IDZ_EXTRA_CONFIGURE_FLAGS to the command line arguments. Therefore you can retry the build as follows:
export IDZ_EXTRA_CONFIGURE_FLAGS=–with-ogg=/Users/idz/idz_builds/libogg/1.3.0/install-iPhoneOS-armv7
idz_configure armv7 6.0 libvorbis-1.3.3/configure
The build should now succeed.

You can repeat the build for any other architectures you may need. For example, to build for the simulator use:
export IDZ_EXTRA_CONFIGURE_FLAGS=–with-ogg=/Users/idz/idz_builds/libogg/1.3.0/install-iPhoneSimulator-i386
idz_configure i386 6.0 libvorbis-1.3.3/configure

Creating the Pseudo-Framework

Building libvorbis creates three static libraries, libvorbis.a, libvorbisenc.a and libvorbisfile.a, however a pseudo-framework can only have one static library, so we need a method to combine these libraries into a single .a file. Luckily static libraries are only object file archives, so this is not hard to do.

Change into the lib directory of one the install directories:

Make a temporary directory to work in and change into it:

Extract the object files from each of the libraries in turn:

Combine all the object files into a new library called libvorbisall.a.

Pop out of the tmp directory and remove it

Since you will need to repeat this process for each architecture it makes sense to generalize this process and create a script automate it. Create the following script file in $IDZ_BUILD_ROOT/bin/idz_combine:

When I have more time I will come back and describe what is going on here line by line.

Using this script, all you need to do to perform the combination step is:
pushd install-iPhoneOS-armv7/lib
idz_combine libvorbisall.a *.a
and repeat this for each of your architectures.

These per-architecture combined static libraries can then be combined using the idz_fw script from the previous tutorial:
idz_fw Vorbis libvorbisall.a install-iPhoneSimulator-i386/include/vorbis

In coming posts, I’ll look at how you can use Ogg.framework and Vorbis.framework to play audio on iOS.

About idz

A professional software engineer dabbling in iOS app development.
This entry was posted in Tutorial. Bookmark the permalink.

2 Responses to Tutorial: Open Source on iOS (Part 4): Compiling libvorbis

  1. favormm says:

    Can you help to compile the opencore-amr, I have successfully compiled on iOS4.0 with xcode 4.2 but faild compiled on iOS6 with Xcode 4.5.

    The source at:

    • idz says:

      If you post the error message you are seeing I might be able to point you in the right direction. You might get a faster response by posting a question on stackoverflow.com.

Leave a Reply