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:
[code]
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.
[/code]
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.
Type:
[code]
libvorbis-1.3.3/configure –help
[/code]
The relevant line is
[code]
–with-ogg=PFX Prefix where libogg is installed (optional)
[/code]
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:
[code]
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
[/code]
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:
[code]
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
[/code]

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:
[code][/code]
pushd install-iPhoneOS-armv7/lib
idz_combine libvorbisall.a *.a
popd
[code][/code]
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:
[code]
idz_fw Vorbis libvorbisall.a install-iPhoneSimulator-i386/include/vorbis
[/code]

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:
    http://sourceforge.net/projects/opencore-amr/files/opencore-amr/

    • 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