0

I have an iOS project with two targets, one is intended to be the full version while the other one will be the lite version. I'm using the following code in order to hide/show features.

#ifdef FULL_VERSION
  NSLog(@"Full version");
#endif 

This works well if I define preprocessor macros at project level, however when I set them at target level they don't work. By the way I'm setting them like this:

Apple LLVM compiler 3.0 - Preprocessing
  Preprocessor Macros    FULL_VERSION

I need to define them at target level in order to know which version is running.

Any ideas why they work only at project level?

2
  • Why are you setting Full version, shouldn't you be setting FULL_VERSION? Commented Aug 8, 2012 at 19:40
  • @GordonDove I wrote it wrong here, but I have FULL_VERSION in both, the code and the preprocessor macro. But I'm still having the issue. Commented Aug 9, 2012 at 16:29

3 Answers 3

1

My problem was that the scheme was not pointing the correct target. Editing the scheme solved the issue.

Sign up to request clarification or add additional context in comments.

Comments

0

Preprocessor definitions do work on targets as expected, overriding or inheriting the project setting.

One common mistake is to set build settings on just one (unused) configuration. Check if you set the preprocessor definition on all configurations.

You can check the build log (Command-7) to see if the correct options are passed to the compiler: Search for -DFULL_VERSION.

2 Comments

I set macros on all configurations: build, release and deployment. Checking the build log I see that the only value passed is the one set on project settings, the value overrrided on the specific target is not passed to the compiler.
Then you are having some other kind of error, a (seldom) bug in your version of Xcode, or simply made a mistake.
0

In your target, for all "PreProcessor Macros" insure that you have the exact same define as you used in your code, to whit "FULL_VERSION" (minus the quotes). Expand the box to be absolutely sure that define is there for every configuration too.

You can actually see what the complier is doing by selecting the right icon in the left pane and select the topmost "Build". Find your file being compile, select that line, then click on the far right icon in that line to see the actual compilation command. I have two Preprocessor define that you can see below. Also, select that huge compile line, paste it into a empty TextEdit window, then search for "-D" - you should see -DFULL_VERSION there. if you do not see you you have not properly entered it in the Build commands - wrong target, wrong config etc. I never saw this feature fail in 8 years of using Xcode.

One of my compile lines:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch i386 -fmessage-length=0 -std=c99 -fobjc-arc … -DUNIVERSAL -DDEBUG=1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk -fexceptions … LTSharing.m -o ...LTSharing.o 

1 Comment

Yes, I do have the same in both. But I'm still having the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.