2

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

user346443
  • 4,672
  • 15
  • 57
  • 80
  • Have you read the release notes for 4.6.3? – abiessu Aug 18 '13 at 02:45
  • All i found was this http://developer.apple.com/library/ios/releasenotes/developertools/rn-xcode/#//apple_ref/doc/uid/TP40001051-SW241 – user346443 Aug 18 '13 at 02:49
  • Look deeper. A developer of code must know the code he/she is developing. You must be familiar with the rules you are operating under, otherwise, you cannot operate. – abiessu Aug 18 '13 at 02:51
  • Any chance you could point me towards a link, or a simple answer. – user346443 Aug 18 '13 at 02:54
  • I am aware that the default complier is now clang on C++11, but i do not understand whats stopping my c++ classes from being linked. – user346443 Aug 18 '13 at 03:03

2 Answers2

2

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.

Nirav Bhatt
  • 6,940
  • 5
  • 45
  • 89
  • Thanks for that. Your answer prompted me to change the .hpp file to .h and my .cpp to .mm which solved the error. – user346443 Aug 18 '13 at 06:27
  • Sure, anytime. Glad to help. If it helped, please mark correct. It will help you get quicker answer in future for sure. – Nirav Bhatt Aug 18 '13 at 06:33
  • On the other hand, if it gave constructive directions, you can upvote (+1) it. These are more direct ways to say thanks on Stackoverflow. – Nirav Bhatt Aug 18 '13 at 06:50
  • It doesn't matter how header files are marked; only source files matter. – newacct Aug 19 '13 at 06:21
0

Solved

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

user346443
  • 4,672
  • 15
  • 57
  • 80