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 Release builds): enter image description here Note that the GCC documentation states -Dname will be defined as 1, so I omitted "= 1" for Release: enter image description here

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

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

If I put #define ADD_CAMERA_FEATURE 1 in the source, #ifdef works as expected, but I also get a warning that I am redefining an existing macro. Thus, Xcode knows that the macro must exist from the assembly schema settings, but still does not include the #ifdef code branch.

Other information:

  • Xcode 5.1
  • OS X 10.9.2
  • iOS 7.1

My goal is to have a goal for creating a version of an iOS 7 application and a goal for creating a version of an application prior to iOS 7, from one source. I have to support older devices that cannot be updated to iOS 7 even longer. There may be a better way to do this. Any suggestions on how to do this would be appreciated.

+6
macros ios objective-c xcode
source share
1 answer

Found a problem. This is due to goals and dependencies. I created a new target to compile the source file and added a preprocessor definition to this target. Then this compiled object was linked into a static library, used as a frame. Therefore, I also created a new target for the static library. Unfortunately, I overlooked that the purpose of the static library still depended on the initial compilation stage, which did not include the definition of the preprocessor. As a result, although I was building the object file correctly, the new object file was not associated with the project at runtime. Therefore, in the "Assembling phases" section for the static library, I needed to change the target dependency to the correct object file, and everything began to work. Thanks to @matt and @StevenFisher for pointing me to the right settings.

enter image description here

+5
source share

All Articles