Is it possible to use .cpp files if I am just using c++ code?

Is it possible to use .cpp files in iOS projects providing I am just using c++ code in there? If I try to just change the extension of the pure c++ code in a .mm file to .cpp the project will break. Is there any openFrameworks configuration file where I can change this?

FYI, the reason for me asking is actually because having it working for .cpp would solve me some problems in a multiplatform setup I am using right now, since .cpp files are the ones I’m using for both Android and OSX.

Any other workaround suggestion would be much appreciated too. As an example, I’ve tried something (apparently) as silly as replacing a main.mm file with only a one-line #include "main.cpp" in which all the code was, but that didn’t work.

Thanks!

The .mm extension tells the compiler to compile in Objective-C++ instead of just C++. While you may not be using any Objective-C in your code directly, you’ll be pulling in Obj-C code from within OF while compiling, which is why it breaks.

You don’t need to use a .mm extension, though. Change your file(s) to .cpp, open the right sidebar, select the relevant file(s) and set the type to Objective-C++.

3 Likes

That worked! Thanks so much @admsyn! Really clear answer. :slight_smile: