如何在objective-c中编译特定文件++以及 Objective-c 中项目的其余部分
我目前正忙于一个项目,需要使用外部配件来读取 Mifare 1k 标签。
该附件附带了一个 SDK,用(Objective?)C++ 编写,我按照提供的说明将 XCode 设置为“将源编译为:Objective-C++”,并在“其他链接器标志”中添加了“-Obj-C++”。
SDK那么编译就可以了,但问题是我已经在项目中使用了几个库(例如 ASIHTTPRequest、JSONKit 等),并且由于这些库中的新设置而出现编译问题,如果我切换回以前的设置,我在阅读器的 SDK 中遇到编译问题
问题是:有没有办法仅将 SDK 中的类编译为 C++,并将项目的其余部分编译为 Objective-C
编辑: SDK 文件包含?仅 .h (和链接库)
感谢您的帮助, 麦克风
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
从文件导航器中选择要编译为 Objective C++ 的文件,然后在文件检查器视图中选择文件类型。这是 Xcode 4 中的情况,但 Xcode 3 中也有类似的机制。
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.
尝试将包含库头文件的文件重命名为 myClass.h(用于接口)和 myClass.mm(用于实现文件)。这会强制将文件编译为 Objective-C++。
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++.
我已经解决了这个问题:
库方法
I have resolved this problem:
the library method
好吧,在构建阶段选项卡中,有一个编译源部分。对于要使用 Objective-C++ 编译器的文件,添加标志:-xobjective-c++
在 Xcode 12.5 中测试
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