How do you add GPUImage to an iOS project?

Lakan Bahande picture Lakan Bahande · Sep 27, 2012 · Viewed 13k times · Source

I am trying to make a camera/photo app that will add a filter on an image. I have heard of Brad Larson's GPUImage and so I downloaded it and tried to manipulate it to be more familiar with the code.

Now, I made a new project in Xcode and added it on my frameworks, but i don't have any idea how to use it on a new project.

How can I properly use GPUImage in my new project?

Answer

Brad Larson picture Brad Larson · Sep 28, 2012

I don't know how I could be much clearer than the step-by-step instructions I put on the very first page of the GitHub project and in the README.md under the section "Adding the framework to your iOS project":

Once you have the latest source code for the framework, it's fairly straightforward to add it to your application. Start by dragging the GPUImage.xcodeproj file into your application's Xcode project to embed the framework in your project. Next, go to your application's target and add GPUImage as a Target Dependency. Finally, you'll want to drag the libGPUImage.a library from the GPUImage framework's Products folder to the Link Binary With Libraries build phase in your application's target.

GPUImage needs a few other frameworks to be linked into your application, so you'll need to add the following as linked libraries in your application target:

  • CoreMedia
  • CoreVideo
  • OpenGLES
  • AVFoundation
  • QuartzCore

You'll also need to find the framework headers, so within your project's build settings set the Header Search Paths to the relative path from your application to the framework/ subdirectory within the GPUImage source directory. Make this header search path recursive.

To use the GPUImage classes within your application, simply include the core framework header using the following:

#import "GPUImage.h"

As a note: if you run into the error "Unknown class GPUImageView in Interface Builder" or the like when trying to build an interface with Interface Builder, you may need to add -ObjC to your Other Linker Flags in your project's build settings.

Also, if you need to deploy this to iOS 4.x, it appears that the current version of Xcode (4.3) requires that you weak-link the Core Video framework in your final application or you see crashes with the message "Symbol not found: _CVOpenGLESTextureCacheCreate" when you create an archive for upload to the App Store or for ad hoc distribution. To do this, go to your project's Build Phases tab, expand the Link Binary With Libraries group, and find CoreVideo.framework in the list. Change the setting for it in the far right of the list from Required to Optional.

Additionally, this is an ARC-enabled framework, so if you want to use this within a manual reference counted application targeting iOS 4.x, you'll need to add -fobjc-arc to your Other Linker Flags as well.

To see this in action, look at any of the many sample applications I ship with the framework.