13 January 2009

An alternative way of using sio2 iPhone SDK

First we must thank the author of sio2 iPhone sdk, who have done a great deal of work to make our life easier. And better yet, it's free. If you are looking for a free iPhone game sdk, please find out more details on http://www.sio2interactive.com. Anyway, if you've reached this blog post, you probably already know of this sdk.

Now, we talk about the issues. It is very powerful and all that, the big issue I have is that the way of using the SDK is pretty primitive. I need to customize based on the template project, which i don't like because it take time to renamed the stuff.
Now if I don't want to follow that approach, I basically have to include all the source files in my project and compile very thing. That is not too bad, until I had to do clean-build frequently. A clean-build (clean first and then build) takes almost a minute on my 20 inch iMac, which is very counter productive.

My solution to this is to create a Cocoa Static Library project out of the sdk source, and reference that static library in my own game project.
Here is a step-by-step guide on how to do so:
  1. Create a Cocoa Static Library project in Xcode. Xcode -> File -> New Project -> Static Library -> Cocoa Static Library, named sio2.
  2. Download sio2 sdk, extract it. In the folder SIO2_SDK_v1.3.1, locate 'src' folder.
  3. In Finder, copy that src (or move if you wish) into the project folder 'sio2'
  4. In Xcode, add the 'src' folder to the newly created project. To do so:
    1. Ctrl click on the project root, Add -> Existing Files -> Select the 'src' folder (note that this is the one in the sio2 folder)
    2. In the confirmation dialog, make sure 'copy items to destination folder' is UNCHECKED
  5. If you try to compile now, you get a few thousand errors, there are a few things you need to do in order make it compile
    1. In Xcode, delete a file named 'sio2_wrap.c' from the 'lua' group. Since I don't know whether this file is going to be useful in the future or not, just choose 'Delete References' when Xcode asks.
    2. Now, select the sio2 group, you will see a bunch of files named like 'sio2_xxxxx.h' or 'sio2_xxxxx.cc'. You need to select all of them (except README.txt) in the top-right view, hit the Get Info icon in the tool bar. In the General tab, change the file type to 'sourcecode.cpp.objcpp'.
    3. In Other Resources, open sio2_Prefix.pch. Replace '#import <Cocoa/Cocoa.h>' with '#import <Foundation/Foundation.h>'
  6. Now build. You get no error but a tiny warning. I assume that is not critical.
  7. Change the configurations, make sure you build for all the following 4 combinations. (if you are targeting 2.1, change version number from 2.0 to 2.1 accordingly).
    1. Device - 2.0 | Debug
    2. Device - 2.0 | Release
    3. Simulator - 2.0 | Debug
    4. Simulator - 2.0 | Release
  8. In Xcode, open your own game project
  9. Ctrl click on game project root, Add -> Existing Files, choose the sio2.xcodeproj we've just created. In the confirmation dialog, make sure 'copy items to destination folder' is UNCHECKED
  10. Once added, you will see a file name 'libsio2.a' under sio2.xcodeproj. Drag that file to Targets -> game_name -> Link Binary With Binaries.
    1. Remember we have built 4 version of the static library?
    2. Xcode is smart enough to know which one to link to, when you change the configuration in your own game project.
  11. Now you need to include a single header file 'sio2.h'. You can locate the header file by either add header search path to your project configuration, OR you may just place the sio2 project folder in parallel with your game folder and use a relative path like this: #import "../../sio2/src/sio2/sio2.h"
  12. You are now good to go. Enjoy the power of sio2 sdk.

If anybody have trouble following the guide, just leave comments below. I will send out copies of the static lib project files

So what do you gain from this approach?
  • Faster building time
  • Cleaner project structure
  • Reusability, use the same static library for multiple game projects is not an issue at all.
  • You don't have to build a project from the 'tempate' project, which is kinda old-school. You get to name your project properly.
  • If the sdk is updated, just replace the 'src' folder in your sio2 static libary project. And then build for the 4 configurations. You don't have to do anything to all your game projects referencing this static library (except for compatabilty check of couse).



---------- Update (15 Jan 2009) ------------
Make sue you select 'Cocoa Static Library' while creating the sio2 project. If 'Cocoa Dynamic Library' is choosen instead, you will get over 2000 compilation errors. That's because we have not link all the frameworks yet. I don't see the point of using a dynamic library yet, so stick to the static way. cheers!



---------- Update (18 Jan 2009) ------------
There are some concerns from sio2 forum about the loss of debug symbols. The answer is debug symbols are not lost.

You will still be able to step into all the sio2 functions and view the value of primitives and structure without any issue. This works for both simulator and device, as long as build config of your game project is set to Debug. Because by doing that, Xcode links the Debug sio2 static library which contains all the necessary debug symbols.

With all that said, it WILL be a bit troublesome if you need to actually modify sio2 static library itself (because you need to open up the sio2 static library project, do some modification and build for all 4 configs).

So i'd say that this way is better for game developers who are using sio2 sdk, but definitely not for sio2 developers.


---------- Update (23 Jan 2009) ------------
For developers who wish to frequently update the sio2 SDK to suit their needs. Remove the group "sio2" (the directly contains all the files start with 'sio2_') from the static lib project, and added it into your game project. Of course the file type must be changed to sourcecode.cpp.objcpp, before everything compiles.

21 comments:

Steve said...

I get 1 warning, and 2277 errors, can you please email me the compiled project files

Steve said...

heres my email:
cheesegrator ... at ... gmail

many thanks!
compiled for 2.0 would be great

André de Brito said...

First of all, thanks very much for this tutorial. It's very useful.

A few clarifications for other users:
- Step 5.2:
Include "sio2.cc" and "sio2.h" as well.

- Step 6 - before compiling:
In the project's "Info -> General" tab, select "Device - iPhone OS 2.0" (or 2.1 or 2.2, depending on what you are using) as the "Base SDK for All Configurations" (otherwise the OpenGLES framework and its headers wouldn't be found).

- Step 11:
All compilable files of the host project (.h, .m, ...) that import "sio2.h" must have their type set to 'sourcecode.cpp.objcpp' ("Info -> General").

Thanks again.

sid said...

i followed the instructions upto step 5....but still i am getting a single warning and 2985 errors.......can u help me out please.......

Vik said...
This comment has been removed by the author.
Vik said...

could you please send me a copy of the static lib project files to

vikthered...at..gmail


Thank you

Red said...

Something else to keep in mind that hung me up for a few minutes: Make sure you include the audio framework OpenAL in your new project.

Kyle James Schultz said...
This comment has been removed by the author.
Wonwoo Lee said...

Hello, I've used SIO2 v1.3.6 without any problems. But with the v1.4, I got the following link error in my application.
( the engine library libsio2.a is built with no problem)

Undefined symbols:
"_sio2Shutdown", referenced from:
templateShutdown() in template.o
"_sio2Init", referenced from:
-[EAGLView createFramebuffer] in EAGLView.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
"_sio2Shutdown", referenced from:
templateShutdown() in template.o
"_sio2Init", referenced from:
-[EAGLView createFramebuffer] in EAGLView.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Do you have any idea for this ?

Wonwoo Lee said...

Hello, I've used SIO2 v1.3.6 without any problems. But with the v1.4, I got the following link error in my application.
( the engine library libsio2.a is built with no problem)

Undefined symbols:
"_sio2Shutdown", referenced from:
templateShutdown() in template.o
"_sio2Init", referenced from:
-[EAGLView createFramebuffer] in EAGLView.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
"_sio2Shutdown", referenced from:
templateShutdown() in template.o
"_sio2Init", referenced from:
-[EAGLView createFramebuffer] in EAGLView.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Do you have any idea for this ?

lyxite said...

looks like some of the symbols referred before has been remove from the 1.4 API.

the error is caused by update of SDK, not because of the way you build.

Wonwoo Lee said...

Hi, I found a solution from the SIO2 forum. The function sio2Init and sio2Shutdown is implemented in the library file libsio2_dev/sim.a. Linking these two files solved my problem.

Wonwoo Lee said...

Hi, I found a solution from the SIO2 forum. The function sio2Init and sio2Shutdown is implemented in the library file libsio2_dev/sim.a. Linking these two files solved my problem.

neil_brightcliffe said...

Hi,

I have managed to build the new sio2 project following these instructions (thank you). How do I link to it as I added a reference to the lib file to myt iphone app project but all I get is 1000+ build errors.

Thanks,
Neil.

Try said...

Hi,

I have tried and created the static library successfully but when i had add it in my existing application then it shows me 500+ errors.

Here is one of the error.

error: expected '=', ',', ';', 'asm' or '__attribute__' before 'btBroadphaseInterface'

Can you please help me?

I have also tried with http://svn.elysium777.com/sio2lib/ library but still i am getting errors.

Thanks,
Dip

Windows 7 Key said...

I'm delighted that I have observed this weblog. Finally anything not a junk, which we go through incredibly frequently. The website is lovingly serviced and kept up to date. So it need to be, thank you for sharing this with us.
windows 7

Menchester said...

Really amazing blog. I appreciate your work. Thanks.
Cheap Web Hosting

Dallas said...

Cool blog. If you need more info on film production companies then this is a great resource.

dsadf said...

nvironmental protection agency officials claimed they along with Ough "We have to incorporate harder safety expectations Oughout Florida coupled with made the particular trip prior Air Max Shoes to, having gourmet dinners fully briefed every evening and also returning home using glaciers boxes stuffed with seafoodInchThey will tasted Tropical isle gound beef having air jordan shoes sweet onion nuts, lobster and spud chowder, pig along with gound beef belly and strawberry shortcake "You realize it is sensible,In The organization stated only Air Jordan one circumstance connected with animals harm a defunct duck was reported, yet Pruessing declared that could not always be verifiedIs actually oil outflow to the Air Jordan Cheap Yellowstone River could possibly extend considerably over and above any 10-mile stretch in the famous waterway, the organization accepted under politics strain MondayThe actual Asian Cheap Nike Air Max navy said later Friday it will increase the actual seek location for children right after selecting a variety of relief firms, in spite of earlier Nike Air Max accounts they were contemplating rotating their particular work to help recouping systems nearly 2 days as soon as the early Weekend morning incident"Michaud stated Bill Air Max 2011 is actually properly trained

Mudassar Shafi said...

The post is so enlightening on the valuable tremendous collection. Read Superbs People will get information and entertainment through your web.Hope you will keep posting Nice writing.

sahib said...

It was very useful for me. Keep sharing such ideas in the future as well. This was actually what I was looking for, and I am glad to come here! Thanks for sharing the such information with us
doctor reviews by patients
find doctor list