Xcode Stepping to Random Lines

Filed under Apple on Friday, 10 October, 2008 1:46 am

Lately I've been having some issues with Xcode's debugger not stepping through in sequential order.

Note: You can skip to the bottom to see the settings you need to set, that stop the debugger to jump around the place randomly.

The point of the debugger is that you can examine variables and program logic, "stepping through" the code, a single line at a time.

In the picture below, you can see a sample from Xcode's debugger.
The way the debugger works is when a breakpoint stops the program's execution, you can view the current values that all the variables hold.
The line that Xcode highlights blue hasn't actually been executed yet, it is just stopped on the line so you can process the logic yourself and then you press continue and check if it executes as you expect.

Xcode variable hover.png

"

"

"

"

In the image above, you can see that the variable "number1" still holds the value of 2. This is because as I said above the debugger has stopped, the blue highlighted line has not been executed and will not be until the debugger moves to the line after it.

On a side note, DO NOT ENABLE ZEROLINK, or for that matter any other compiling optimisations such as SSE3 or Fast, etc. If you do, you will have weird problems with the debugger stepping through lines of code in the random orders.
What I mean by this is that the debugger will not step from the current line to the next line and the next. It will go to random lines in a seemingly random order. The reason this happens is because zerolink causes optimisations in the compiled application. The problem with this is the human understandable order of line by line gets thrown away and you therefore cannot debug using your logic.

You can check if Zerolink is enable by selecting:
"Project > Edit Active Target".
"

EditActiveTargetXcode.png

"

"

"

"

"

"

"

"

"

"

"

"

"

"

"

You can disable Zerolink by double clicking on the word "YES", or whatever it says then simply type NO.

Zerolink.png

"

"

"

"

"

"

"

"

"

"
"

"

"

"

"

"

"

"

"

"

"

Update:

Sorry about the long article on something so simple. I've decided not to delete the above as there are some parts that you may find useful (and pretty pictures!). After playing around with different settings I believe i've figured out the settings that actually matter."

Make sure the following have been set:

1) Instruction Scheduling = None
2) Optimization Level " " " = None [-O0]
3)
ZERO_LINK " " " " " " " " "= None

The second thing you need to be careful of is that Xcode has 2 areas these settings can be set:

Project Settings: "Project > Edit Project Settings"
Target Settings: ""Project > Edit Active Target"

It is useful being able to have separate settings for the Project and the Target. However, the Target settings OVERRIDE the Project settings. So it is best to change the Target settings, not the Project settings.

If I discover any other settings that apply, I will update this post. If you see any mistakes or would like to add anything, leave a comment and i will update it :)

OpenGL GLUT Application Template

Filed under Apple on Thursday, 21 August, 2008 2:15 am

Here is a downloadable template to create an OpenGL GLUT Application (using an app bundle) for the people who haven't figured out how to use Xcode 100% as yet.

There area Xcode templates freely available for SDL OpenGL projects but not for GLUT so I'm providing this one myself. I think I found this on a MacRumors thread so I cannot take credit for this but anyway, enjoy.

48AAFD8E-1EDA-4522-A24E-F1A50746E5D4.jpg

Brock

How To use Dynamic Libraries in Xcode 3.1 (using FMOD)

Filed under Apple on Thursday, 21 August, 2008 1:12 am

I am writing this article to help people running Xcode on Mac OS X get around the dreaded FMOD dynamic libary not found error from happening at runtime:

dyld: Library not loaded: @loader_path/../Frameworks/libfmodex.dylib
Referenced from: /Users/brock/Game/Debug/mine.app/Contents/MacOS/mine
Reason: image not found

So here we go, the first step is to install FMOD Ex Programmers API. You can download it here:
http://www.fmod.org/index.php/download

Once you have downloaded it, run the FMOD Installer.
Once installed, all FMOD resources should be located:

/Developer/FMOD Programmers API/

The dynamic libraries that you will need to include with your application will be located in:

/Developer/FMOD Programmers API/api/lib/

You should drag the library you wish to use into your Xcode project"s Framework folder so that it looks like:

Picture 2.png

Once you have completed your FMOD coded application in Xcode, you will need to create a shell script that Xcode will automatically run upon completion of building your .app bundle.

If you are compiling a shell tool, which doesn"t encapsulate all the project"s code, this will still work, but you will need to modify the code below by removing the .app path stuff where appropriate.

In order to get rid of the dreaded dylib not found error, then you will need to run the otool command as well as creating a script for Xcode to run after everything is built. The otool command will tell you where your application is expecting to find the libraries and frameworks that it looks for at runtime.
So, type this:

otool -L /path/to/AppName.app/Contents/MacOS/AppName

which should produce something like:

./libfmodex.dylib (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/GLUT.framework/Versions/A/GLUT (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
@executable_path/../Frameworks/SDL.framework/Versions/A/SDL (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/OpenAL.framework/Versions/A/OpenAL (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.4.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.0.0)

Notice the top line, this means that the application expects to find:
"./libfmodex.dylib". Which is our FMOD dylib file.
However this will not exist at runtime, so we have to get Xcode to copy this file into the app bundle as well as modify the binary to look in its new location:

So, in Xcode, right-click on your target and choose:

Add > New Build Phase > New Run Script Build Phase

Picture 3.png

You should see a new item under the target called "Run Script":

Picture 4.png

Now, Double-click the "Run Script" folder and paste in the following command:
WARNING! If you are copy pasting this be sure to change the the curly quotes " " into normal quotes by simply re-typing them.

mkdir "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Frameworks"
cp -f /Developer/FMOD Programmers API/api/lib/libfmodex.dylib "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Frameworks/libfmodex.dylib"

install_name_tool -change ./libfmodex.dylib @loader_path/../Frameworks/libfmodex.dylib "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/$PRODUCT_NAME"

Picture 6.png

You will need to modify this script according to your own setup.
Xcode will also inform you of any errors with your script in the Build Warning and Errors window when you build your project.

You should do a clean then do a build. After the build is complete Xcode will run the script.
Step by step what this script does it:

1) Creates a new directory called "Frameworks" inside the application"s bundle
2) Copies the "libfmodex.dylib" file from the FMOD developer folder to the /Frameworks directory that was just created.
3) And lastly the install_name_tool command will modify the application binary to look for the library in the new location.

Thanks for reading my little tutorial on this. This process was really not as straight forward as it ought to be so I wanted others to benefit from this (as well as myself should I ever forget how to do this!). Any questions or if you would like me to change anything please login and leave a comment.

If you liked this article and would like to download a copy for reference you can download it:

Download a zipped iWork Pages document 834AB2CD-A0EB-40EB-B650-DD5F73B2FEAE.jpg
Download Pages Download PDF

Cheers
Brock

Linking Errors with C++ in Xcode

Filed under Uncategorized on Tuesday, 5 August, 2008 1:57 am

If you're programming C++ classes and happen to get a linking error similar to this:

ld: symbol(s) not found
collect2: ld returned 1 exit status
"RTSUserInterface::UserInterface::UserInterface()", referenced from:
RTSnamespace::MainMenu::MainMenu()in mainMenu.o
RTSnamespace::MainMenu::MainMenu()in mainMenu.o
"RTSUserInterface::UserInterface::~UserInterface()", referenced from:
RTSnamespace::MainMenu::MainMenu()in mainMenu.o
RTSnamespace::MainMenu::MainMenu()in mainMenu.o
RTSnamespace::MainMenu::~MainMenu()in mainMenu.o
RTSnamespace::MainMenu::~MainMenu()in mainMenu.o
RTSnamespace::MainMenu::~MainMenu()in mainMenu.o
RTSnamespace::MainMenu::~MainMenu()in mainMenu.o
RTSnamespace::MainMenu::~MainMenu()in mainMenu.o
RTSnamespace::MainMenu::~MainMenu()in mainMenu.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Build failed (2 errors)

The problem is that you haven't written the body for your class constructors and destructors in your implemenation (.cpp) file. I consider this a reminder.

Switching Between Tabs in Safari

Filed under Uncategorized on Sunday, 22 June, 2008 10:09 pm

Safari Web Browser

Apple don't make this obvious in Safari's preferences pane, however after some digging I figured out you can actually switch between tabs using the keyboard:

   <- Switch to Left Tab               Switch to Right Tab ->
Command + Shift + [               Command +Shift + ]

 

Update: Tha Shell suggested a way where you can configure the keys you want to use to switch tabs...

Step 1: Go to System Preferences > Keyboard & Mouse > then choose the Keyboard Shortcuts tab
Step 2:  Press the + key at the bottom of the window:

Do the same as above, but now type 'Select Previous Tab' and assign a key as before.

Voila! you can now switch between tabs with a keyboard shortcut that you prefer. I wasn't able to get command + right/left to work, if you get it to work, let me know by leaving a message :)

 

Realistic Video Game Characters

Filed under Uncategorized on Saturday, 17 May, 2008 3:01 pm

An artist has created images of how Mario, Bowser and Sonic would look like in real life.

I love the Mario one although it's quite creepy.

RealMarioRealBowserRealSonic

via Essenmitsosse 

Ward Cunningham on Floss Weekly 27

Filed under Uncategorized on Thursday, 3 April, 2008 4:38 pm

podcast_5.jpg

FLOSS Weekly, a podcast to which I listen regularly, has some really prestigous and interesting guests who are usually, really great programmers such as the famous Ward Cunningham. He is a Perl and Smalltalk programmer and the inventor of the Wiki. Ward appears on Floss Weekly, Episode 27.

This episode is a really interesting insight into one of the most important programmers in the Open Source community who speaks about programming, how he invented modern Extreme/Agile programming and his techniques for designing software.

Another really interesting individual in the open source and gaming community is Ryan Gordon. Ryan is a games porter who has ported games such as Postal 2 to the Mac. You can find him at icculus.org he has appeared on an older episode of Floss Weekly, Episode 8. This is my favourite episode of Flossy Weekly to date. This is definately worth a listen, especially if you want to know about porting games or some interesting bits about programming in general.

Subscribe to Floss Weekly