9

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.

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.

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.

Screenshot of target build settings for modules

socaljoker
  • 204
  • 2
  • 11

3 Answers3

8

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

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

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

Good luck.

Community
  • 1
  • 1
user3510132
  • 91
  • 1
  • 5
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Mamoun Benghezal Aug 06 '15 at 08:22
  • Yes, only #import works. Could not get modules working due to the same error described here. #import works – FranticRock Aug 04 '17 at 02:04
6

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

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

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

That's it, then simply use #include in your .mm files for the specific headers you need. For me that meant:

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

Hope this helps someone :)

Baggers
  • 3,146
  • 17
  • 30
  • I've done this. Same error in the newly added .m Objective-C file. I have no .mm files. Checked everything outlined in this thread. Still same error. Xcode 8.3 – FranticRock Aug 04 '17 at 02:01
3

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

Worked for me.