XCode woes
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:
ionEngine.xcodeProj
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
and the cpp file
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
ion::MouseHandler::Create();
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
Claire
I have an XCode project (created as an empty project) that contains two targets as follows:
ionEngine.xcodeProj
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
Code:
#pragma once
namespace ion
{
class MouseHandler
{
public:
static void Create();
private:
MouseHandler();
~MouseHandler();
};
}
and the cpp file
Code:
#include "MouseHandler.h"
namespace ion
{
void MouseHandler::Create()
{
printf("MouseHandler::Create called.\n");
}
}
In ionTest my Cocoa based test application I call the function
ion::MouseHandler::Create();
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
Claire
Sounds like the cpp file isn't being compiled at all... is there a tick next to it in the files view?
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.
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.
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.
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.
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.
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.
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
Xcode 4 migration woes.. | SparkyNZ | 3 | 14,012 |
Sep 23, 2013 12:00 AM Last Post: naeem.paracha |
|
XCode Woes | DesertPenguin | 4 | 6,407 |
Sep 11, 2007 01:22 PM Last Post: TomorrowPlusX |
|
XCode 2.0 linker woes ( Tiger ) | TomorrowPlusX | 2 | 5,221 |
May 2, 2005 07:20 AM Last Post: TomorrowPlusX |