8

I created a new cocoa application in Xcode with 3 *.m files (main.m, AppDelegate.m, and projectnameTests.m). In order to to use object-cpp, I renamed the 3 *.m files to *.mm files.

Then I get this following error from Xcode:

"Undefined symbols for architecture x86_64: "_NSApplicationMain", referenced from: _main in main.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 have never dealt .o files, so am not sure what's wrong. Please help.

P.S.: I use the latest Xcode, version(6.1.1).

3
  • 2
    You only need to change the file that you're going to be writing the C++ code in. Change back the main.m file back to a single m. Commented Jan 31, 2015 at 2:38
  • Thank you for your replying. I know that. I should change only main.m to main.mm to use object-cpp. But I want to know what causes this error. Commented Jan 31, 2015 at 3:17
  • I think you misunderstood. You shouldn't be changing the main.m file to .mm. Only the file you're going to write C++ code in should you change to .mm Commented Jan 31, 2015 at 3:40

1 Answer 1

12

Add AppKit.framework to the "Link Binary With Libraries" section under the Build Phases for your project target, and that should fix the problem.

P.S. Don't ask me why XCode automatically finds the necessary framework (i.e. AppKit.framework) for .m files but not for .mm files, but adding AppKit.framework fixes the issue because NSApplicationMain is defined in AppKit. Adding Cocoa.framework also fixes the issue, likely because it triggers XCode to automatically link with AppKit.framework.

Sign up to request clarification or add additional context in comments.

2 Comments

How you figured this out, I'll never know. Absolutely brilliant. I was racking my brains for an hour until I found your answer. It all started when I wanted to rename AppDelegate.m to AppDelegate.mm.
Life saving answer!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.