There is a library that causes build errors when the project builds for the simulator.
Is there a way to set a flag in the build settings or somewhere else to make the compiler NOT link the specific library when building for the simulator?
This could be done by creating a new Target, but I would prefer not having to create a whole new target.
What would be the most convenient solution for something like this? (which works both in XCode 4 and 5)
You can #ifdef out the #import calls to the library using:
#ifdef TARGET_IPHONE_SIMULATOR
#import <...>
#endif
If you do that then the code won't try to link with the library.
Related
I've been trying to integrate GCM into my existing iOS project via Cocoapods. Upon building, I've been having compilation errors complaining about "#import errors..." with "...modules disabled". I do have modules enabled, except that the issue is happening since I have a mix of .m and .mm (Objective-C++) files where modules are not supported (this has already been raised by others).
I'm able to suppress the error in some files using the preprocessor flag "GMP_NO_MODULES" that's provided (e.g. in GGLInstanceID.h)
#if GMP_NO_MODULES
#import <Foundation/Foundation.h>
#else
#import Foundation;
#endif
but other required header files (e.g. GGLConfiguration.h) do not have the flag built-in.
Did anyone find any short-term solutions around this?
I don't think there is any way to fix this right now since there are internal files that do not seem to respect this flag. Although GCM folks are going to come up with an update to the library very soon, that should fix this.
Why not adding GMP_NO_MODULES=1 in your Project or Target Preprocessor Macros?
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.
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.
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 :)
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.
I'm looking to create a precompiled header file, to avoid having to include the same debug and tracking libraries in every header in the project.
I've created a file called -Prefix.pch:
#ifdef __OBJC__
#import "Blah.h"
#import "Blarg.h"
#endif
and added it to the project. Is there anything more I'm supposed to do, or should things just work now (assuming I do a project clean and recompile)?
Set the target's build settings as follows:
GCC_PRECOMPILE_PREFIX_HEADER=YES
GCC_PREFIX_HEADER="Prefix.pch"
Note that you can plop these keys in the Build Settings search field, if you prefer to use Xcode's UI for your build settings.
I got this error in my flutter app when using the library flutter_inappwebview and tried to set deployment version of ios in Runner > General to 12.0.
I set it back to 11.4 and it built with no problems.
I am using the GData static library in my app that uses ARC. Google's instructions say to link the header files from the library to the project target.
The problem is that when I do so I get compiler errors as the GData library is not compatible with ARC.
Google states that:
ARC Compatibility
When the library source files are compiled directly into a project that uses ARC, then ARC must be disabled specifically for the library sources.
To disable ARC for source files in Xcode 4, select the project and the target in Xcode. Under the target "Build Phases" tab, expand the Compile Sources build phase, select the library source files, then press Enter to open an edit field, and type -fno-objc-arc as the compiler flag for those files.
(reference)
But since I have only the header files I can not use this flag in the app target.
Well I asked and found the unswear 10 minutes later. Any way if it will help someone:
The problem is only with the .h files, Goole remark is only for cases you embed the library not as static library.
After someone reported the problem to google, they added new macros that solve the problem, this is how:
search the header files for file named : GDataDefines.h
and add this code inside:
//
// Simple macros to allow building headers for non-ARC files
// into ARC apps
//
#ifndef GDATA_REQUIRES_ARC
#if defined(__clang__)
#if __has_feature(objc_arc)
#define GDATA_REQUIRES_ARC 1
#endif
#endif
#endif
#if GDATA_REQUIRES_ARC
#define GDATA_UNSAFE_UNRETAINED __unsafe_unretained
#else
#define GDATA_UNSAFE_UNRETAINED
#endif
Then in the GDataObject.h which causes the ARC errors
Change the GDataDescriptionRecord struct to
typedef struct GDataDescriptionRecord {
NSString GDATA_UNSAFE_UNRETAINED *label;
NSString GDATA_UNSAFE_UNRETAINED *keyPath;
GDataDescRecTypes reportType;
} GDataDescriptionRecord;
And the
__weak GDataObject *parent_; // parent in tree of GData objects
to
GDataObject GDATA_UNSAFE_UNRETAINED *parent_;
This is the link to google update:
http://code.google.com/p/gdata-objectivec-client/source/detail?r=712
That's it.
Hope it will help someone
Shani
I'm having some issues when compiling my app to iOS.
I'm using sqlite3 and imported as
#import <sqlite3.h>
Well, I only found a file named libsqlite3.0.dylib in my Mac and I copied it to my project.
When I compile it for iOS Simulator, it works just fine. However, when I try to compile the app for iOS Device, it throws an error (Apple Match-O Linker Error) in every call I do in my implementation to sqlite's function (such as _sqlite3_open, etc.)
How can I compile it to iOS Device?
Thank you!
Instead of simply copying the library, do it like this:
in Xcode Navigator, click on your target (the upmost entry)
go to Build Phases, then Link Binary With Libraries
add the libsqlite3.dylib from it's location at /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOSxx.sdk/usr/lib/
Just in case someone faced that same problem as me. If you are unit testing your code, add the lib file also to your test target.
Did you try to import sqlite3 library like:
#import "sqlite3.h"
instead of:
#import <sqlite3.h>
The best way that I have found to use SQLite in your IOS application is to build your own copy of the SQLit library and include it in your project. libsqlite3.0.dylib is a very old copy of SQLite.
You can easily download the SQLite Amalgamation source code and build it for IOS. this gives you the latest SQLite source code that has all the latest bug fixes and improvements.
If you can open Xcode and create a new static library project, then you are 75% of the way there.
Once you have the static library project, include the SQLite sources that you downloaded from the SQLite Amalgamation and set a few Preprocessor options and your off and running with the latest code.
For complete details and sample source code you can visit my blog conedogers