C++ source files must have a recognised extension; .cpp
, .cxx
, .cc
etc. and they will be compiled as C++ files. You shouldn't need to change the file type manually if the extension is correct (and recognised) when you add the file. The compilation language is determined on a per-module basis.
Intermixing C++ and Objective-C is a different story. There's a whole section in the ADC documentation on Objective-C++ (which uses the .mm
extension). So if you want to call C++ code from Objective-C, it will need to be done from a .mm
module.
Given the error you quoted, it looks like you're probably trying to include a C++ header file in an Objective-C module. To make this work, you need to rename the Objective-C module to .mm
and then the compiler will treat it as Objective-C++.
It takes a little planning to determine a clean boundary between the C++ and Objective-C code, but it is worth some up-front thinking.
This article is worth reading: