Igor Karpov Igor Karpov - 3 months ago 24
C Question

Xcode 7: Set Preprocessor Macros per architecture

I need to set

Preprocessor Macro
in
Xcode
just for specific architecture (arm64). How can I do this?

There is similar question here on Stackoverflow: Xcode 6: Set Preprocessor Macros per architecture.
But in my case
Xcode 7
just doesn’t let me to choose the architecture. Tried on
Xcode
versions
7.1.1
and
7.3.1
with the same result: the only architecture option offered by Xcode is “*” (see the picture below).
Preprocessor settings section

Just in case here are my Architectures settings:
Architectures settings section

To give you more understanding why do I actually need this:
I use 3rd-party C-library which relies on a flag set to tell it if it is running on a 32-bit or 64-bit platform.
Note from library's integration guide: “When building for the 64-bit architecture, the
_64BIT
macro must be added in the pre-processor macro section of Xcode.”

So here is what I've tried:


  • to find a way to set architecture-specific macro in Xcode UI (described above)

  • to amend
    .pbxproj
    file manually by replacing
    GCC_PREPROCESSOR_DEFINITIONS
    [arch=*] with
    GCC_PREPROCESSOR_DEFINITIONS
    [arch=arm64] (didn’t give desired effect)



Do you have any ideas what is wrong with my
Xcode
settings, why doesn’t it show architecture options in
Preprocessor
section? Or are there other ways to configure macro in my case?

Answer

Finally I've figured it out.

Achieved result: _64BIT macro would be added during preprocessing to every (at least known for today) 64-bit environment, regardless of is it a simulator of 64-bit device or a real 64-bit device.

The solution is to manually edit .pbxproj-file as follows:

            GCC_PREPROCESSOR_DEFINITIONS = (
                "DEBUG=1",
                "$(inherited)",
            );
            "GCC_PREPROCESSOR_DEFINITIONS[arch=arm64]" = (
                "$(inherited)",
                _64BIT,
            );
            "GCC_PREPROCESSOR_DEFINITIONS[arch=x86_64]" = (
                "$(inherited)",
                _64BIT,
            );

So here is debug-config:

  • first section defines default macros which would be applied for all architectures;
  • 2nd and 3rd define custom macros which would be applied to specific architecture only.

Then changes that you've done manually would be visible within Preprocessor settings editor. It really looks like bug in Xcode in the editor.

You can notice that I've already tried this approach before posting the question, but I've misinterpreted the results of my attempt. The thing is that I've tested my app on the simulator, and architectures are different on real device and corresponding simulator. I've configured macro to be included on arm64 architecture, but simulator's actual architecture was x86_64.

For further reference, this article explains where does every architecture actually take place:

  • arm7: Used in the oldest iOS 7-supporting devices
  • arm7s: As used in iPhone 5 and 5C
  • arm64: For the 64-bit ARM processor in iPhone 5S [and I believe the same is for newer iPhones]
  • i386: For the 32-bit simulator
  • x86_64: Used in 64-bit simulator

For i386 and x86_64 "bitness" of simulated device is implied here, not your Mac's.