xcode 如何在objective-c++中编译特定文件,在objective-c中编译项目的其余部分
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5756209/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to compile specific files in objective-c++ and the rest of the project in objective-c
提问by Themikebe
I'm currently busy on a project where I need to use an external accessory to read Mifare 1k tags.
我目前正忙于一个需要使用外部附件读取Mifare 1k 标签的项目。
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.
该附件提供了一个用 (Objective ?)C++ 编写的 SDK,我按照提供的说明将 XCode 设置为“将源代码编译为:Objective-C++”,并在“其他链接器标志”中添加了“-Obj-C++”。
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
SDK 编译得很好,但问题是我已经在项目中使用了几个库(例如 ASIHTTPRequest、JSONKit 等),并且由于这些库中的那些新设置,我遇到了编译问题。如果我切换回以前的设置,我会在阅读器的 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 ?
问题是:有没有办法只将 SDK 中的类编译为 C++,将项目的其余部分编译为 Objective-c ?
Edit:the SDK files consists only of .h (and a linked library)
编辑:SDK 文件仅包含 .h(和一个链接库)
thanks for your help, Mike
谢谢你的帮助,迈克
采纳答案by Marko Hlebar
Try renaming the files where you are includingthe library headers to myClass.h for interface and myClass.mm for implementation files. This forces the files to be compiled as objective-c++.
尝试将包含库头文件的文件重命名为用于接口的 myClass.h 和用于实现文件的 myClass.mm。这会强制将文件编译为objective-c++。
回答by Casey Fleser
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.
从文件导航器中选择要编译为 Objective C++ 的文件,然后在文件检查器视图中选择文件类型。这是在 Xcode 4 中,但在 Xcode 3 中也有类似的机制。
回答by dale
I have resolved this problem:
我已经解决了这个问题:
- You should set "According to file type" to "Complile Sources As",
- Set "-ObjC++" to the "Other Linker Flags"
- The last,you should modify the files's suffix to .mm that reference the library method
- 您应该将“根据文件类型”设置为“编译源为”,
- 将“-ObjC++”设置为“其他链接器标志”
- 最后,您应该将引用库方法的文件后缀修改为 .mm