iDevGames Forums
XCode woes - Printable Version

+- iDevGames Forums (
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Tools & Technology (/forum-10.html)
+--- Thread: XCode woes (/thread-3532.html)

XCode woes - icklefrelp - Jan 25, 2007 07:30 AM

I'm having a strange problem with XCode and was wondering if anyone here knows the solution.

I have an XCode project (created as an empty project) that contains two targets as follows:

ion - BSD static library (written in C++)
ionTest - Cocoa Application (Objective-C++ / C++)

In the Products group, libion.a is set as a member of target ionTest

I've stripped everything down to the bare minimum and I'm still getting the problem.

The header file MouseHandler.h

#pragma once

namespace ion
    class MouseHandler
        static void Create();



and the cpp file

#include "MouseHandler.h"

namespace ion
    void MouseHandler::Create()
        printf("MouseHandler::Create called.\n");
I've stripped all the code out of this function so it doesn't actually do anything but the results are the same as when the code exists.

In ionTest my Cocoa based test application I call the function


When I compile this in Release (or Debug with ZeroLink disabled) at Link time I get an undefined symbol error for ion::MouseHandler::Create().

However if I create a seperate project for example extIonTest.xcodeproj - which contains a Cocoa Application that links with my static library libion.a

I don't get the link errors and calling ion::MouseHandler::Create() works as expected.

I really don't understand what is going on. libion.a contains other classes, some of which are singleton's that have static member functions for initialisation and these work fine, for example I have a Keyboard handler that is initialised in the same way. It just seems to be this file that is causing me problems.

As a quick test before posting I replaced my MouseHandler class code with the KeyHandler class code (which is working fine) and did a quick Find / Replace to rename everything to MouseHandler and it still won't compile???

Anyone any ideas? It's bonkers.

Many thanks


XCode woes - OneSadCookie - Jan 25, 2007 01:09 PM

Sounds like the cpp file isn't being compiled at all... is there a tick next to it in the files view?

XCode woes - icklefrelp - Jan 26, 2007 04:04 AM

Yes the cpp file is checked. I wish it was that simple.

The odd thing is, it works fine linking a totally seperate project with the static library but linking with the library from a target contained within the same project simply doesn't, even if I drag exactly the same libion.a file into the project to link it that way.

I'll have a play around over the weekend and see if I can recreate the problem in the simplest case. If I still have the same problem, I can post the xcodeproj somewhere as someone may be able to spot something I'm doing wrong.

XCode woes - icklefrelp - Jan 29, 2007 10:13 AM

Ok, I've fixed the problem, which basically stems from me not knowing how to use XCode properly. Yes I know RTFM and all that.

My test app was linking with an old version of my library in /usr/local/lib and not with the libion.a from my Project that I was expecting. Unfortuanatly the old version of the library didn't contain the Functions I was trying to call.

A quick readup on Target Dependencies told me everything I need to know.

XCode woes - djork - Jan 30, 2007 10:13 AM

Is this perhaps a situation where it would make sense to build your library as an OS X framework? It makes these issues much simpler in the long run.

XCode woes - OneSadCookie - Jan 30, 2007 12:05 PM

You should generally use static libraries if you don't *need* a framework or dynamic library. I don't believe it makes anything simpler to use a framework.