Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCode 5.1 preprocessor macro not working

I cannot get this macro to compile the correct code.

Here is the code: enter image description here

Here are the build settings (I'm doing a Release build): enter image description here Note that the GCC documentation says -Dname will define as 1, so I omitted the "=1" for Release: enter image description here

Here is the compile log showing that the definition (in yellow) was passed along on the command line: enter image description here

Here is my output log showing that the code is compiled as if ADD_CAMERA_FEATURE is not defined: enter image description here

If I put #define ADD_CAMERA_FEATURE 1 in the source, the #ifdef works as expected, but I also get a warning that I am redefining an existing macro. So XCode knows that the macro should exist from the build scheme settings, but still does not include the #ifdef branch of code.

Other details:

  1. XCode 5.1
  2. OS X 10.9.2
  3. iOS 7.1

My objective here is to have a target for building iOS 7 version of the app and a target for building a pre-iOS 7 version of the app, both from the same source. I have to support older devices that cannot be upgraded to iOS 7 for a while longer. Perhaps there is a better way to go about this. Any suggestions about how to accomplish this would be appreciated.

like image 603
Chuck Krutsinger Avatar asked Mar 12 '14 17:03

Chuck Krutsinger


1 Answers

Found the problem. It has to do with targets and dependencies. I created a new target to compile the source file and added the preprocessor definition to that target. That compiled object then got linked into a static library being used as a framework. So I also created a new target for the static library. Unfortunately, I overlooked that the static library target was still depending on the original compile step that did not include the preprocessor definition. As a result, even though I was building the object file correctly, the new object file was not the one being linked into the project at runtime. So under Build Phases for the static library, I needed to change the target dependency to the correct object file and everything began to work. Thanks @matt and @StevenFisher for pointing me toward the right settings.

enter image description here

like image 159
Chuck Krutsinger Avatar answered Oct 15 '22 11:10

Chuck Krutsinger