I cannot get this macro to compile the correct code.
Here is the code:
Here are the build settings (I'm doing a Release build): Note that the GCC documentation says -Dname will define as 1, so I omitted the "=1" for Release:
Here is the compile log showing that the definition (in yellow) was passed along on the command line:
Here is my output log showing that the code is compiled as if ADD_CAMERA_FEATURE is not defined:
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:
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With