Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
$
like image 473
american-ninja-warrior Avatar asked Oct 29 '25 02:10

american-ninja-warrior


1 Answers

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

like image 187
Ken Thomases Avatar answered Oct 31 '25 00:10

Ken Thomases



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!