Can't get CocoaServer to build


I can’t get CocoaServer to build. I’m running OS X 10.7.3, Xcode 4.3. No doubt it’s something simple I’m leaving out. But I can’t get around this link error:

Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_HTTPServer", referenced from: objc-class-ref in CocoaServerAppDelegate.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

I wonder if someone can check to see if this happens to them. You don’t have to re-do the whole project. It’s 2 lines of code, or simply copy and paste. It’ll take someone two minutes, tops, and any insight would be sorely appreciated.

  1. Make a new project (Mac OS X Cocoa Application), call it CocoaServer (just to match my code below). You can leave ARC on or turn it off. It doesn’t matter.

  2. Drag the HTTPServer and TCPServer .h & .m files into the project and check the box that says to copy them. [As you recall, we get these files by downloading the code at and looking in the solutions directory for the CocoaServer project.] You should now have the following files in the project:

  3. In CocoaServerAppDelegate.h, add
    #import "HTTPServer.h"
    so that it looks like this:

[code]#import <Cocoa/Cocoa.h>
#import “HTTPServer.h”

@interface CocoaServerAppDelegate : NSObject
@property (assign) IBOutlet NSWindow *window;

  1. In CocoaServerAppDelegate.m, simply alloc/init an HTTPServer:

[code]#import “CocoaServerAppDelegate.h”
@implementation CocoaServerAppDelegate
@synthesize window = _window;

  • (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    HTTPServer *server = [[HTTPServer alloc] init];

The sample code compiles just fine. But my code won’t link. What am I doing wrong?



Doesn’t look like HTTPServer is compiling so either there is an code error (but that’s unlikely if the sample compiles) or it’s not getting included.

Check the “Compile Sources” in the Build Phases tab on the CocoaServer target and make sure that the HTTPServer.m file is in there.
If not then you can add it with the + button.

When you copied the files across did you have the Add To Targets ticked? - this will add the file automatically.



That was precisely my problem. I had not added HTTPServer to the target. The panel had that option unchecked, and I hadn’t paid attention.

Thanks a million. :mrgreen:

Not to defend my silly overlook, but it seems baffling to me that you can add code to a project, #include that code, reference that code… and then the IDE plays deaf, dumb, & blind like that. (Almost as baffling, I suppose, as someone trying to learn programming and thinking he’s allowed to avoid learning about compilers, so maybe I should just brace up). I think I can imagine situations where you wanted to add code files to your project without adding to target. But not adding to target just strikes me as the wrong default. Ah well.