Themikebe
Themikebe

Reputation: 475

How to compile specific files in objective-c++ and the rest of the project in objective-c

I'm currently busy on a project where I need to use an external accessory to read Mifare 1k tags.

The accessory was provided with an SDK, written in (Objective ?)C++ and I followed the instructions provided to set XCode to "Compile sources as: Objective-C++" and added "-Obj-C++" in "Other linkers flags.

The SDK compiles fine then, but trouble is I am already using several libraries in the project (such as ASIHTTPRequest, JSONKit, ...) and I get compilation problems because of those new settings in those libraries. If I switch back to the previous settings, I get compilation problems in the reader's SDK

The question is: is there a way to compile only the class from the SDK as C++ and the rest of the project as objective-c ?

Edit: the SDK files consists only of .h (and a linked library)

thanks for your help, Mike

Upvotes: 17

Views: 16942

Answers (4)

Juraj Antas
Juraj Antas

Reputation: 2712

well, in Build phases tab, there is a section Compile sources. For file you want to use Objective-C++ compiler add flag: -xobjective-c++

tested in Xcode 12.5

Upvotes: 0

Marko Hlebar
Marko Hlebar

Reputation: 1973

Try renaming the files where you are including the library headers to myClass.h for interface and myClass.mm for implementation files. This forces the files to be compiled as objective-c++.

Upvotes: 7

dale
dale

Reputation: 311

I have resolved this problem:

  1. You should set "According to file type" to "Complile Sources As",
  2. Set "-ObjC++" to the "Other Linker Flags"
  3. The last,you should modify the files's suffix to .mm that reference the library method

Upvotes: 6

Casey Fleser
Casey Fleser

Reputation: 5787

Select the file you want to compile as Objective C++ from the file navigator, and then select the File Type in the file inspector view. This is in Xcode 4, but there is a similar mechanism in Xcode 3.

Selecting File Type from the file inspector

Upvotes: 25

Related Questions