xcode 如何将 .mm 文件添加到项目中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10063490/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:54:40  来源:igfitidea点击:

How to add a .mm file into the project?

xcodeobject

提问by user705414

I need to add a .mm file which contains both ObjectC and C++, I am wondering how to do it using XCode 4?

我需要添加一个包含 ObjectC 和 C++ 的 .mm 文件,我想知道如何使用 XCode 4 来做到这一点?

回答by Hyman

There are absolutely no issues in doing that, just add the .mmfle to the project and XCode will compile it as Objective-C++.

这样做绝对没有问题,只需将.mm文件添加到项目中,XCode 就会将其编译为 Objective-C++。

The only caveat is that the .hassociated with that ObjC++ code must not contain any C++ specific code or every file in which that header is included must be .mmtoo.

唯一需要注意的是,与该 ObjC++ 代码关联的.h不得包含任何 C++ 特定代码,或者包含该标头的每个文件也必须是.mm

This because XCode will use different compiler according to the single file, so if a .mis found it will try to compile it as plain ObjC and not ObjC++. You can force to compile it with che ObjC++ compiler but I suggest you to follow the principle described or rename other files to .mmjust to avoid getting things complicated.

这是因为 XCode 将根据单个文件使用不同的编译器,因此如果找到.m它将尝试将其编译为普通 ObjC 而不是 ObjC++。您可以使用 che ObjC++ 编译器强制编译它,但我建议您遵循所描述的原则或将其他文件重命名为.mm以避免使事情变得复杂。