Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use object-Cpp in Xcode

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

like image 776
nextu bonbo Avatar asked Jan 31 '15 02:01

nextu bonbo


People also ask

How do I create a .cpp file in Xcode?

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.

How do I create a .MM file in Xcode?

You just need to change the extension to . mm. There is no option to create a file with . mm extension in Xcode.


1 Answers

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.

like image 172
Arda Avatar answered Sep 23 '22 00:09

Arda