xcode “禁用模块时使用‘@import’”错误 - 启用模块和链接框架 = YES

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

"Use of '@import' when modules are disabled" Error - Enable Modules & Link Frameworks = YES

iosxcodemodulecocoapods

提问by socaljoker

I have a project that uses CocoaPods and uses the 'SCLAlertView-Objective-C' pod. That pod uses the @import UIKit;module style import. I've set "Enable Modules (C & Objective-C)" and the "Link Frameworks Automatically" to YES in both my target and project settings. I am still getting the "Use of '@import' when modules are disabled" error.

我有一个使用 CocoaPods 并使用 'SCLAlertView-Objective-C' pod 的项目。该 pod 使用@import UIKit;模块样式导入。我在目标和项目设置中都将“启用模块(C 和 Objective-C)”和“自动链接框架”设置为 YES。我仍然收到“禁用模块时使用‘@import’”错误。

Is there anything that could prevent Xcode from being able to enable Modules such as the use of a .pch file, any linker flags, or anything else I haven't mentioned? I also tried to clean the project and the project build folder. That didn't have any effect.

有什么可以阻止 Xcode 启用模块,例如使用 .pch 文件、任何链接器标志或我没有提到的任何其他内容?我还尝试清理项目和项目构建文件夹。那没有任何影响。

Also worth noting is that my project has multiple targets and also has a deployment target of iOS 7.0. My Base SDK is set to iOS 8.3.

另外值得注意的是,我的项目有多个目标,并且还有一个iOS 7.0的部署目标。我的基础 SDK 设置为 iOS 8.3。

Screenshot of target build settings for modules

模块的目标构建设置的屏幕截图

回答by user3510132

I guess your project contains XXX.mm files, however, the xcode only enable C and objective-c modules.

我猜你的项目包含 XXX.mm 文件,但是,xcode 只启用 C 和 Objective-c 模块。

Please have a look at this answer for your reference: Using @import in objective C in conjunction with __cplusplus

请查看此答案以供参考: 在目标 C 中使用 @import 与 __cplusplus 结合使用

my solution is modify the @import xxx into #import .

我的解决方案是将 @import xxx 修改为 #import 。

Good luck.

祝你好运。

回答by Baggers

I just solved this in a primarily ObjC++ project I was working on that needed to use Firebase.

我刚刚在一个主要的 ObjC++ 项目中解决了这个问题,我正在处理这个需要使用 Firebase 的项目。

Simply make a ObjC (.m) file which contains the following.

只需制作一个.m包含以下内容的 ObjC ( ) 文件。

#import <Foundation/Foundation.h>
@import Firebase; // << swap this for your specific import

That's it, then simply use #includein your .mmfiles for the specific headers you need. For me that meant:

就是这样,然后只需#include在您的.mm文件中使用您需要的特定标题。对我来说,这意味着:

#include <"Firebase/Firebase.h">
#include <"FirebaseAuth/FirebaseAuth.h">

Just to stress the point, no amount of fiddling with link options made any difference to this "Enable Modules (C & Objective-C)"was already YES. Upgrading to XCode7 didn't seem to help.

只是为了强调这一点,没有与链接选项摆弄量对此做出任何区别"Enable Modules (C & Objective-C)"已经YES。升级到 XCode7 似乎没有帮助。

Hope this helps someone :)

希望这对某人有所帮助:)

回答by theHyman

The build option does not really work as it should. I've solved this problem by adding -fcxx-modules (Objective C++) or -fmodules (Objective C) manually to "C Flags"/"C++ Flags".

构建选项并没有真正发挥应有的作用。我已经通过将 -fcxx-modules(Objective C++)或 -fmodules(Objective C)手动添加到“C Flags”/“C++ Flags”中解决了这个问题。

Worked for me.

对我来说有效。