AUC WWDC 2009 Photos

Filed under Apple + WWDC on Saturday, 13 June, 2009 2:57 pm

I have a collection of photos from our exciting trip sponsored by the AUC to Apple's WWDC 09 Conference in San Francisco. Check it out here.

Compile and Use Boost Libraries in Xcode & Visual Studio

Filed under C++ on Thursday, 29 January, 2009 1:06 am
Boost.png

A quick note on Boost. If you want to use the Boost libraries, the good news is that you can just #include the boost classes that you want to use in your code (see bottom for Boost usage in code).
However if you want to use libs such as Boost::Filesystem or Boost::iostreams, they MUST be compiled into a library file. This is accomplished with the bjam tool which is kinda like an easy to use compiler for Boost instead of using GCC.

I can't believe that there are no tutorials on the net for compiling Boost on Mac OS X. I got it compiled for Visual Studio 2005 after reading numerous articles and then I adapted it for Mac OS X. Actually it's pretty easy to compile on Mac, a little easier than it was on Windows...OK, here we go!

Download Bjam and the Boost source from http://www.boost.org/

Compiling for Xcode 3.1:

1. You need to download and copy bjam.exe to

/usr/sbin

This will make the command available in the Terminal.
If it does not, check your paths in ~/.profile using vi or TextEdit. Find the line that starts with export PATH= and copy bjam to one of the paths listed (note: each path is separated by a colon ":")

2. CD to the boost directory (for example):

cd ~/Desktop/Boost/boost_1_37_0

3. To compile for Visual Studio 2005 as static release libs:

bjam toolset=darwin variant=release threading=multi link=static

4. The static debug version:

bjam toolset= darwin variant=debug threading=multi link=static

NOTE: If you want dynamic libraries (.dylib files instead of .a files) then use"link=shared instead of"link=static.

This will take a while (maybe 20 minutes) to run each of the above commands, and you"ll need both.
A Note about the naming of the output files:

Building with link=static gives you files with the following naming convention:

libboost_filesystem-xgcc40-mt-d-1_37.a

Building with link=shared gives you files with the following naming convention:

libboost_filesystem-xgcc40-mt-1_37.a

Including Boost in your C++ code

#include<iostream>
#include<boost/any.hpp> // any is an actual library

C++ Usage

boost::any a(5);
a = 7.67;
std::cout << boost::any_cast <double> (a) << std::endl;

Using the Compiled Libraries in Xcode

Using the libraries can be accomplished by dragging the static (.a) lib files to tyhe Xcode project. If you really want to use dynamic library files, then you will need to drag to the Xcode project, and also have a script run after the binary is built.
This is because dynamic libraries need to be copied inside the .app bundle because they are linked to at runtime, as opposed to compile time for static libs.

The actual process of scripting the dylib copy and modifying the darwin executable are already covered in another article I wrote here: How To use Dynamic Libraries in Xcode 3.1

Using the Header files in Xcode

Okay, it's getting to be all a big pain in the ass now, but we're almost done.

The headers can usually be dragged to the Xcode project for individual .h files. However because the Boost headers are in nested folders, it's a lot easier to just add the path to the Xcode project.

Go to: Project | Edit Project Settings | Build tab | User Header Search Paths
Add the path to where Boost is located on your hard disk. A good place is to put it somewhere inside the /Developer folder or /usr/local/include/. Also DO NOT check the "Recursive" option. It won't work if you do.

It's up to you where you want to put it....

Xcode User Header Search Paths

Compiling for Visual Studio 2005/2008:

1. You need to download and copy bjam.exe to

C:Windows\system32

2. CD to the boost directory:

cd C:Program FilesBoostboost_1_37_0

3. To compile for Visual Studio 2005 as static release lib (use"msvc-8.0 for VS 2008):

bjam toolset=msvc-8.0 variant=release threading=multi link=static

The static debug version:

bjam toolset=msvc-8.0 variant=debug threading=multi link=static

Here is a dynamic dll, debug runtime version (for Visual Studio 2008). It will produce files with the following file name convention:" 'libboost_math_c99-vc90-mt-sgd-1_37.lib'

bjam toolset=msvc-9.0 variant=debug threading=multi runtime-link=static

This will take a while (maybe 20 minutes) to run each of the above commands, and you"ll need both.
A Note about the naming of the output files:
Building with link=static gives you files with the following naming convention:
boost_filesystem-vc80-mt-1_37.lib

Building with link=shared gives you files with the following naming convention:
libboost_filesystem-vc80-mt-1_37.dll

Update: Other options for compiling Boost with Bjam

Within the final build of the libraries, you will get a lib file like the following:
'libboost_math_c99-vc90-mt-sgd-1_37.lib'

The "lib" prefix is for static libraries. Use link=static
The 's' letter is to static linking to runtime. Use runtime-link=static
The 'd' is debug, use variant=debug
The 'g' is using debug runtime, to enable this you will need: runtime-debugging=on.

For more information, you can find the official documentation for building Boost here:

http://www.boost.org/doc/libs/1_38_0/more/getting_started/index.html

Well, thats it. Thanks for reading and if you have anything to add please leave a comment below (Sorry about the registration, I get too much spam otherwise).

Cheers,
Brock

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 :)

 

« Previous PageNext Page »