Getting Speex Lib to Compile in Xcode

I had to use AudioQueue to play Speex, and I had a very hard time importing the Speex library, and making it compile with Xcode. Therefore, I want to write down the steps I did to make it compile, just in case I need it in the future.

  1. Go to http://www.speex.org/downloads/, and get the latest stable version. When I did this, it was 1.2rc1.
  2. Once downloaded, you should see that it contains an “include” folder, and a “libspeex” folder. Drag and drop that into your Xcode project.
  3. Clean and Build. You should see a lot of errors!

  4. Go back to the downloaded Speex folder, and look for config.h.in. Removed the “.in”, and keep it as a “.h” file. Drag and drop the config.h into Xcode as well.

  5. Go to your project’s .pch file, and insert this:
    #define HAVE_CONFIG_H
  6. In config.h, make sure FLOATING_POINT and USE_SMALLFT are #define, instead of #undef
  7. In config.h, look for, SPEEX_EXTRA_VERSION, SPEEX_MAJOR_VERSION, SPEEX_MICRO_VERSION, SPEEX_MINOR_VERSION, and SPEEX_VERSION. Those should all have a prefix of #undef. Comment out those lines. These are redefined in arch.h.
  8. You should see a lot of errors like this: “Lexical or Preprocessor Issue: speex/speex.h file not found”. For errors like this, instead of using

    #import “speex/speex.h”
    use
    #import “speex.h”
    Make sure you are also using double quotes “” instead of < >

  9. Remove the echo_diagnostic.m file.

  10. Clean and build again. There are still plenty of errors. It should all be something like:

    Parse Issue Unknown type name ‘EXPORT’
    Go to config.h, and make sure EXPORT is #define instead of #undef

  11. Now you should see just two more errors:

    Linker command failed with exit code
    and
    error: unable to open executable …..

In your libspeex folder, you will see that testdenoise.c, testecho.c, testenc.c, testenc_uwb.c, testenc_wb.c, and testjitter.c all have a main function. Comment out the main functions, or delete those files. I deleted those files on my project.

While we’re at deleting stuff, we might as well delete Makefile.am and Makefile.in in “include” folder. Delete them again in the “include/speex” folder.

You should now be able to compile speex library in Xcode without errors.