american-ninja-warrior
american-ninja-warrior

Reputation: 8185

objective-c: How to use NSApplicationMain

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)
$

Upvotes: 4

Views: 2709

Answers (1)

Ken Thomases
Ken Thomases

Reputation: 90531

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).

Upvotes: 3

Related Questions