45

In the zxing iphone project the readme states:

  • It can happen that when trying to build your own project with ZXingWidgetController you get linker errors like "undefined reference to". If this error looks like a c++ undefined reference, then renaming main.m into main.mm (Objective-C++ source suffix) may fix the problem

It did indeed. But I'm wondering why?

Cœur
  • 37,241
  • 25
  • 195
  • 267

2 Answers2

82

.mm extension stands for Objective-C++, when compiler can process C++ classes. But when using .m extension it will be able to compile only C code, without C++ classes.

Nickolay Olshevsky
  • 13,706
  • 1
  • 34
  • 48
7

Both .m and .mm are class file extensions of source code for Mac-based applications. .m files can contain both Objective-C and Objective-C++ classes. To avoid conflicts between the two in mixed-use scenarios there's the convention to rename all Objective-C++ class files to .mm. This helps compilers to distinguish.

So in a project which uses both Objective-C and Objective-C++ you will see:

  • .m files containing Objective-C
  • .mm files containing Objective-C++
schmijos
  • 8,114
  • 3
  • 50
  • 58