(Solved) Integrate C++ code with Objective C in XCode

 

XCode is a IDE which works only on MAC systems. XCode provides support to program in Objective-C language, C, C++, OpenGL and etc.. Objective-C codes are saved in .m format, C files in .c and C++ files in .cpp format. But when you try to integrate C++ code with Objective-C code, then XCode shows an error. This is because Objective-C code performs late binding but C++ code performs Compile time binding. So there will be mismatch with the compiler. 

Techspace provides you a solution with which you will be able to integrate C++ files with Objective-C code. When you try to include "iostream" file in C++, XCode shows an error saying "iostream" file cannot be found. The solution for this is to save ".c" or ".cpp" file in ".mm"  format. 

".mm" specifies that instead of compiling with Objective-C compiler, compile the file with default c++ compiler. Now if you come across error saying any of the import or include files not found, then change the Objective-C file which is currently saved in ".m" format to ".mm". Now clean the project and re-build and run. This should work without any errors. 

Please post your comments below if you still get errors and find difficulty in finding solution for the problem. Stay tuned for lot many solutions.