4

Whats wrong with this program?

// main.m
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>


int main(int argc, char *argv[])
{
    return NSApplicationMain(argc, (const char **)argv);
}

I try to compile and get this error:

$ clang -framework Foundation main.m
Undefined symbols for architecture x86_64:
  "_NSApplicationMain", referenced from:
      _main in main-c04948.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
$
american-ninja-warrior
  • 7,397
  • 11
  • 46
  • 80

1 Answers1

3

You've linked against Foundation, but not AppKit or Cocoa. NSApplicationMain() is part of AppKit. You need to replace -framework Foundation with -framework AppKit or -framework Cocoa (they are more or less synonymous).

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
  • so let's say I have a class called NSFoo() and I want to know which framework it is part of, how do I find that out from the internet? – american-ninja-warrior Jan 09 '16 at 03:35
  • You look it up in Apple's reference documentation and look for the import statement in the upper-right corner. For example, the [class reference for `NSButton`](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSButton_Class/) says to `@import AppKit;`. That's the newfangled way of saying `#import `. It also indicates that you need to link against the AppKit framework. Also notice that the breadcrumb trail in the upper left indicates that the document is part of the AppKit Framework Reference. – Ken Thomases Jan 09 '16 at 03:57