libsndfile is an open-source C library to allow programmers to read and write sound files via a simple, standard interface. It handles many formats: WAV, AIFF, Octave, PAF, etc. You, the programmer, don’t have to worry about the dirty business of headers, endian-ness, etc. — libsndfile takes care of all that invisibly.
Getting libsndfile to work with XCode projects is fairly straightforward, but in case you (like me) are never quite sure what you’re doing, the following overview may be helpful.
Note: By default, the Finder hides root-level directories (/usr, /lib, /etc, etc.,) from dialog boxes. To work with libraries like libsndfile, you have to make them visible.
- Compile
libsndfileaccording to the instructions in the README and INSTALL files. Note that the default installation putssndfile.hin/usr/local/include, and the library itself in/usr/local/lib. - Create a new XCode project
- Copy
make_sin.cfrom thelibsndfile“examples” directory into your project. - Tell
XCodewhere to find the include file:- Project → Edit Project Settings
- Click “Build”
- In “Collection” popup, select “Search Paths”
- Double-click “Header Search Paths” and add the path
/usr/local/includeif it’s not already listed there. Leave the “Recursive” checkbox unchecked. - Click “OK”.
- Double-click “Library Search Paths” and add the path
/usr/local/libif it’s not already listed there. Leave the “Recursive” checkbox unchecked. - Click “OK”
- Close the Project Info window.
- Add the library to your project:
- In the project window, select the project icon in the “Groups and Files” pane.
- Project → Add to Project… (or control-click the project icon).
- Navigate to the library you wish to include (probably
libsndfile.a. If you want to copy the library to your project (why would you??), click the checkbox. Click “Add.”
- Compile your project. You may have to do some minor tweaking to
make_sin.cto get it to compile. For example, I had to change this:
int main (void)
to this:
int main (int argc, char * const argv[])
That’s all there is to it.
Addendum 070201: After I upgraded to XCode 2.3, the link editor had some problems linking to this library. See Loader issues, above.