null
null

Reputation: 1197

XCode thinks C++ files are C when building for iOS?

I am working on a C++ project in XCode 5.1.1. The project compiles fine for OSX, but when I build for iOS I am hitting a problem. The compiler is producing errors that suggest it thinks some files are in C, and not in C++. The files in question all appear to be header-only files with no corresponding cpp file.

As background, the project is based on Cocos2d-x 3.0, and compiled for iOS fine a couple of weeks ago. Since then I added jl_signals which makes use of FastDelegate, which I know does some non-standard things that are beyond my understanding.

These are some of the errors I'm getting:

namespace fastdelegate {

...produces the errors:

[...]/jlsignal/FastDelegate.h:142:1: Unknown type name 'namespace'
[...]/jlsignal/FastDelegate.h:142:23: Expected ';' after top level declarator

Also, problems finding the standard library:

#include <new>

...produces the error

[...]]/jlsignal/ScopedAllocator.h:7:10: 'new' file not found    

This stack overflow question suggests that the compiler is trying to build the project as c and not c++, which seems to fit the symptoms, but it seems strange that it is isolated only to this one particular library.

I am wondering if there is some build phase or XCode specific tickbox somewhere I have neglected. Thanks.

Any suggestions would be very appreciated.

EDIT: Some people have suggested that I rename the file from .m to .mm, but the file is a .h header file so I can't follow this advice. All the other C++ files in the project are .cpp files, and the project has definitely been compiling successfully as C++ until I added this library.

EDIT 2: OK I have got it working. It turns out that the advice about .m vs .mm was right after all. It all came down to the fact that in Cocos2d-x the ios build has a separate main file from the mac build, which was called main.m. I changed it to main.mm and all was well. The entire project is in c++ so the compiler was figuring it out somehow, but something was getting tripped up here.

Upvotes: 1

Views: 977

Answers (1)

Almo
Almo

Reputation: 15871

Xcode activates the c++ compiler for any files named filename.mm. I'm guessing your file is named filename.m.

Upvotes: 4

Related Questions