Skip to content

Working with libpd in Xcode

Dan Wilcox edited this page Mar 2, 2018 · 6 revisions

Working with libpd using Xcode is designed around the libpd static library Xcode project found at the root of this repository: libpd.xcodeproj. It contains all of the files & settings needed to build & link the libpd C library as well as the Obj-C wrapper.

Note: If you prefer letting CocoaPods handle these details for you, you can use the libpd CocoaPods pod file.

Nutshell

You want to add the libpd.xcodeproj to your Xcode project so it can automatically build libpd for you.

Details

The following contains the basics of manually adding the libpd.xcodeproj to an Xcode project using Xcode 4+.

These steps follow the basic requirements for adding a static library project to any Xcode project, so if you have done this before, it should be familiar. If this process is new, you will be able to replicate it when adding any other open source library that provides an xcodeproj.

This overview involves:

  1. Downloading and placing libpd & it's source files
  2. Adding libpd.xcodeproj to your Xcode project
  3. Adding the required libpd header search paths to your Xcode project
  4. Adding the C++ wrapper to your project (optional)

Note: These steps may change in future if Apple makes any major Xcode interface changes.

Download

Download or git clone the libpd repository to your computer and place it in a location relative to your project.

A good option is to put it in a subfolder of your main project folder. Let's say we created a new Xcode project called "MyProject":

MyProject/
MyProject/MyProject.xcodeproj <- your Xcode proejct (created by Xcode)
MyProject/MyProject <- contains all your build files (created by Xcode)
MyProject/libpd <- **you could put libpd here**

Add

Now open your Xcode project file, which is "MyProject" in this example, and perform the following steps. You should only need to do this once to set everything up.

  • Drag the libpd.xcodeproj file from the Finder into your project (drop it in the Project Navigator pane on the left)
  • Go to project settings by clicking on your project's blue icon, then select the main target of your app under "Targets"
  • Under "Build Phases", then "Target Dependencies", click the plus icon and add libpd
  • Under "Build Phases", then "Link Binary With Libraries", click the plus icon to choose the frameworks/libraries we need to add.
    • For iOS: add libpd-ios.a, AVFoundation.framework, and AudioToolbox.framework
    • For OSX: add libpd-osx.a
  • Under "Build Settings", find the entry "User Header Search Paths", & add a recursive entry for your base libpd directory (in this case libpd as it is within our MyProject folder)

Now you should be able to build libpd and include the libpd C header "z_libpd.h" or the Obj-C wrapper header "PdBase.h".

What these steps do:

  1. Added the libpd.xcodeproj to your Xcode project as a dependency, which means your main project depends on building libpd.
  2. Set your main project to link the libpd library once it is built, again because it is a dependency. If you see errors about missing references to "libpd_...", etc then you most likely missed the "Link Binary With Libraries" step.
  3. Added the required search paths needed to find the libpd header files. If you see an error saying something like "z_libpd.h, PdBase.h, m_pd.h, etc... not found", then you probably missed this step.

C++ Wrapper

If you want to use the C++ wrapper with the libpd.xcodeproj, you will need to do a few more steps as the C++ files are not included in the Xcode project.

  • Drag the libpd/cpp folder from the Finder into your project (drop it in the Project Navigator pane on the left)
  • In the "Choose options for adding these files:" sheet that appears, select "Create groups" & check the checkbox next to your project's build target, then hit Finish.

This essentially adds the C++ wrapper classes to your project's build files. You should now be able to include the C++ wrapper's "PdBase.h" header to your C++ headers.

Note: All libpd language wrappers require the core libpd C library to function.

iOS Notes

HAVE_LIBDL

Apple forbids applications which allow dynamic linking which includes libpd's external object loading code. By default, the libpd.xcodeproj does not set the Pd HAVE_LIBDL compiler flag which is required to compile the object loader. If you manage your Xcode project manually, make sure you do not add this flag to your compiler options, otherwise your app may be rejected by Apple ala:

...your app uses or references non-public APIs, which is not permitted on the App Store. Specifically, your app's PdBase class (which appears, but is not guaranteed, to be part of the Pure Data libpd library) implements the non-public selector _setup from the CoreSpeech.framework. It would be appropriate to remove this reference before resubmitting for review.

Related Info

Clone this wiki locally