HiJack In the Box – Part 2 – iPhone HiJack Tutorial

August 21, 2011

Part 1 | Part 2 | Part 3

This would be a lengthy post and if you would have questions, you an post a comment below.

Now we’ve seen that we can easily integrate an analog sensor (resistive type) on our Part 1, this time our goal will be to make the default OpenGL ES iPhone project template, which is a colored bouncing box, to be controlled with the HiJack device. But on this part, we will first setup our solution, because linking with HiJack is a bit tricky!

First, we can get the source code from the HiJack source tree. There are resources online on how to use SVN, but this will be the least of our worries on this demo.

Pasted Graphic

(yeah I pasted their webpage, but anyway…)

When you’re done with getting the code through SVN, you can see that there is a LibHiJack directory present under the iPhone directory. This is the code that we are to use to reference on our project:

Screen shot 2011 08 21 at 10 14 25 PM

Let us start creating a new iOS project, an OpenGL ES Application:

3 $ Pasted Graphic

(you can try to run it and you will see a bouncing grandien-ty box)

When the project is created, we will import the LibHiJack’s files to our project. I tried to reference the LibHiJack’s output which is a static library (“.a”) and the HiJackMgr.h header file, but it will be a bit redundant because we will still need to reference the other header files (“.h”). I thought of using the entire code from the other project instead.

Create a new group named “Lib”:

5 $ Pasted Graphic

From the LibHiJack project, drag all of the source files (as seen below) except the .pch (precompiled header) to our new project, under the Lib group. Be sure also to mark the files as “Copy” so we will not ruin the original files:

6 $ Pasted Graphic

After this, I know you are itching to build the project, so let us build it! But sadly there will be some nasty errors again:

7 $ Pasted Graphic

With this, I made a quick comparison with the LibHijack project, and the aurioTouch Oscilloscope project included along when you get the files (which build nicely). Go to the project file and go to the Build Settings tab button. Also while at it, select the “Levels” view so we can see what the default Xcode settings are and what we will be putting:

8 $ Pasted Graphic

The first setting we will change (as what I have seen with the other projects) is the “Compile for Thumb”. Let us change it to “No”:

9 $ Pasted Graphic

Then the “Optimization Level” on the Debug setting, change it to “Fastest [-O3]”:

10 $ Pasted Graphic

Symbols Hidden by Default = “Yes”

11 $ Pasted Graphic

Language Dialect = “C99 [-std=c99]”

12 $ Pasted Graphic

Clear “Other C Flags”

13 $ Pasted Graphic

Clear “Preprocessor Macros”

14 $ Pasted Graphic

Then this is the required part, we would have to add a User-defined value. This can be done by expanding the “Add Build Setting” context menu and selecting “Add User Defined Setting”. Indicate the value as shown below:

15 $ Pasted Graphic

Ok then now, I think it should work! Let us try to build it:

16 $ Pasted Graphic

But ohno! It seems that it looks for a framework, so I looked at the aurioTouch Oscilloscope code and checked what framework is needed. We would need to add AudioToolbox.framework. To do this, click again the project and use the “Build Phases” tab button to see the “Link Binary with Libraries” section. This is where we would add the framework:

17 $ Pasted Graphic

Using the “+” sign, a selection window will show up and then look for AudioToolbox.framework. Select it and use the “Add” button to add it to the list:

18 $ Pasted Graphic

Then we can now build the app again!

20 $ Pasted Graphic

Whew!

So let us now use the “HiJackMgr.h” header and put it on any implementation (“.m”) file and try to build it. Let us try putting it on HiJackInTheBoxAppDelegate.mm:

Screen shot 2011 08 21 at 10 35 41 PM

But…

21 $ Pasted Graphic

Ohno not again!! Those cryptic errors!

But don’t worry its not our fault. Upon searching around a number of resources, it turns out to be that the code is not compiling C++ code, which our darling LibHiJack was built upon. To resolve this, we would have to rename the HiJackInTheBoxAppDelegate.m to HiJackInTheBoxAppDelegate.mm:

22 $ Pasted Graphic

Then build it again:

23 $ Pasted Graphic

Cool! now it works!

So now we are done with setting up the project! This post is getting long so I will write out the next part, the actual HiJack code on Part 3.

(trust me, I had taken an entire day and dumped a lot of solutions to the trash to come up with this setup that worked)

;

About these ads

5 Responses to “HiJack In the Box – Part 2 – iPhone HiJack Tutorial”

  1. Have you tried this solution with Xcode4.2 and iOS5.0?

    I followed you instructions and changed the default compiler vim LLVM back to GCC but I got the following errors now. A lot of them:

    /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSString.h:12: error: stray ‘@’ in program

    Cheers,
    Michael.

  2. grundyoso said

    I just got this to work with Xcode4.3.2 using the iOS SDK 5.1. Most of the instructions above worked except I kept getting these ARC errors:

    Cast of C pointer type ‘void *’ to Objective-C pointer type ‘HiJackMgr *’ requires a bridged cast
    ‘NSAutoreleasePool’ is unavailable: not available in automatic reference counting mode
    ARC forbids explicit message send of ‘release’

    To fix I changed:

    Project->Build Settings->CompilerLanguage->Objective-C Automatic Reference Control = YES

    Target->Build Settings->CompilerLanguage->Objective-C Automatic Reference Control = YES

    With that I was able to successfully build.

  3. Narcis said

    Could you please post a tutorial on how to integrate libhijack for xcode 4.6? I did everything as in this tutorial, but it still gives me many errors. Thank you!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: