subzero subzero - 2 months ago 8
C++ Question

force to compile a specific file as Objective-C/file type, but the entire project as Objective-C++

I'm adding some features to a project that already exist. It works as expected.

Then I added few files from an open library to that project.

Now, Xcode fails to compile the whole project.

Investigating why, I found out that the problem is the "Compile source as" flag, it is set by default to "Objective-C++".

Switching that flag to other value makes Xcode to complain. Hundreds of errors in any case.
I have the idea the previous dev did this to avoid renaming .c, .cpp, .m to .mm. He is not here anymore. So, hard to say.

Any idea how to solve this?
I see few options:


  1. Either I rename the files as necessary. Which means hundreds of
    files renamed. Or

  2. I force Xcode to compile a specific file as
    Objective-C/file type, but the entire project as Objective-C++ Or

  3. I create a small project, and then produce a shared library.



I would like to continue with option 2. Is it possible? and how?

Any other idea?

Thanks

Answer

I went thru the easiest way: forcing Xcode to compile a specific file as Objective-C, but the entire project as Objective-C++.

Added the compiler flag -x objective-c to each file in Build Phases> 'Compile source as'