Friday, December 3, 2010

Xcode Linking Problem: symbol(s) not found

The discussed problem

For my recent iPhone Xcode Cocoa project I setup mogenerator to autamtically get the classes created that match an entity in the xcdatamodel. When I later tried to use those objects in my ViewControllers I couldn't get the application build.

The error said something a long the lines:

Undefined symbols:
   "_OBJC_CLASS_$_Recipes", referenced from:
       objc-class-ref-to-Recipes in RootViewController.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Whereas "Recipes" stands for one of my entities in my CoreData datamodel.

The fix of the linking error

It took me hours to figure this one out. In XCode if you click on your project root in the Groups & Files View (normally on the left of the XCode window), you can see (on the right hand side of the XCode window) the list of all files in the project. As you can see below in the picture.

Make sure that in the last column of the list for each .m file (especially for the once that caused the error) the box is checked. If the box is checked the file is included in the default target that gets build.

The reasons for linking errors

If you never change anything in the target files and/or related build configuration, all your new classes should be included in the build of the target automatically.

The file that caused my error was generated with the mogenerator. The generator creates a subfolder in your Xcode project and it seems to me like all the files in there are not automatically added to the target.


Post a Comment