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).
Select New Project, then under OS X select Command Line Tool, and select C++ as the language. You'll have a single main. cpp source file to start with. To create more C++ source files for your project, use New > File and select C++ File under Source for OS X.
You just need to change the extension to . mm. There is no option to create a file with . mm extension in Xcode.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With