zantoku / google-toolbox-for-mac

Automatically exported from code.google.com/p/google-toolbox-for-mac
Apache License 2.0
0 stars 0 forks source link

Unit-Tests in a static library (includes patch) #24

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
We are building the Unit-Tests as a static library and link this into test 
project.
The app will crash because GTMIPhoneUnitTestDelegate is not present.

----
2009-05-25 18:59:22.633 RABSQLite[23586:10b] *** Assertion failure in 
UIApplicationMain(), 
/SourceCache/UIKit/UIKit-738/UIApplication.m:1084
2009-05-25 18:59:22.634 RABSQLite[23586:10b] *** Terminating app due to 
uncaught 
exception 'NSInternalInconsistencyException', reason: 'Unable to instantiate 
the UIApplication 
delegate instance. No class named GTMIPhoneUnitTestDelegate is loaded.'
2009-05-25 18:59:22.636 RABSQLite[23586:10b] Stack: (
    2484961451,
    2486152763,
    2484960907,
    2493939445,
    816221235,
    61549,
    8210
)
----

The file is only referenced by name and never used, the linker strips the 
delegate.
When using the delegate inside the main function this problem is solved,

----
int main(int argc, char *argv[]) {
  NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

  // Ensures that the app delegate will be linked correctly.
  [GTMIPhoneUnitTestDelegate description];

  int retVal = UIApplicationMain(argc, argv, nil, @"GTMIPhoneUnitTestDelegate");
  [pool release];
  return retVal;
}

---

This little change will have no negative effects and helps to use the 
Units-Tests as a static 
library.

Max

Original issue reported on code.google.com by mcz...@gmail.com on 25 May 2009 at 5:04

Attachments:

GoogleCodeExporter commented 9 years ago
The linker doesn't pull over objective c classes/categories, by default, you 
need to use -ObjC when linking in a 
static library of Objective C.  
http://developer.apple.com/qa/qa2006/qa1490.html  Also covered in the man 
pages for gcc.

Original comment by thoma...@gmail.com on 25 May 2009 at 5:10

GoogleCodeExporter commented 9 years ago
Thank you, that solved the problem.

Original comment by mcz...@gmail.com on 3 Jun 2009 at 6:52