Undefined Symbols for custom C++ classes in Xcode 4.6.3. Works in Xcode 4.5.2

1.8k Views Asked by At

I have an iOS app that works fine in Xcode 4.5.2 but in Xcode 4.6.3 i get undefined symbols for my custom c++ classes.

SomeClass.hpp

class SomeClass{
public: 
    SomeClass();
    void doStuff();
}  

SomeClass.cpp

#include "SomeClass.hpp"

SomeClass::SomeClass(){ 
    // ra ra ra
}
SomeClass::doStuff() { 
   // ra ra ra
}

CallingClass.mm

#include "SomeClass.hpp"

@implementation CallingClass

-(void) execute{
    SomeClass someObject;
    someObject.doStuff();
}

@end

Error

Undefined Symbols for arm7:
SomeClass::SomeClass() referenced from:
-[CallingClass execute:] in CallingClass.o

The .hpp files are set to C++ Headers, the .cpp files are set to C++ Source, and the .mm files are set to Objective-C++ Source.

Each of the .cpp files are present in Build Phases/Compiled Sources.

libc++.dylib is included in the project for a library that i'm using.

The 4.6.3 C Language Dialect is c11 while in 4.5.2 its C99[-std=c99]. The C++ Language Dialect and C++ Standard Library are set to Compiler Default in both version of Xcode.

The compiler is Apple LLVM 4.2 in Xcode 4.6.3 while its LLVM 4.1 in 4.5.2.

Any guidance would be highly appreciated.

Cheers

2

There are 2 best solutions below

4
On

I had faced similar problem, and here is what I did to solve:

1 - Specify -fobj-arc flag against respective mm file in Build Phases section (this is optional and may not work always)

2 - Ensure that wherever .mm (or it's .h file) is included, that source is also marked as Objective-C++ Source and vice versa. I know it's bit tricky to do trial and error, but the basic principle is to maintain same compilation options for the file tree being included.

0
On

Solved

I changed the .hpp files to .h and the .cpp files to .mm.