Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 510
Themikebe Avatar asked Apr 22 '11 14:04

Themikebe


People also ask

How is Objective-C compiled?

Objective-C compiles into machine code. Remember that the language (Objective-C, C, C++) only defines the rules to correctly write code. The compiler checks to see if your code is correct and compiles it, i.e., translates it into executable code.

How do I open an Objective-C project in Xcode?

Click on the Xcode icon in the dock to launch the tool. Click Next and on the resulting options panel name the project sampleApp and select Foundation from the Type menu. Also verify that the Use Automatic Reference Counting option is selected.

Can you call C++ code from Objective-C environment?

This link says that as long as the Objective-C class calling the C++ class has been converted to a . mm (Objective-C++) class then the two should work nicely together.


3 Answers

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

like image 138
Casey Fleser Avatar answered Nov 02 '22 19:11

Casey Fleser


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++.

like image 27
Marko Hlebar Avatar answered Nov 02 '22 19:11

Marko Hlebar


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
like image 32
dale Avatar answered Nov 02 '22 19:11

dale