Xcode 7:为每个体系结构设置预处理器宏 [英] Xcode 7: Set Preprocessor Macros per architecture

查看:154
本文介绍了Xcode 7:为每个体系结构设置预处理器宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要为特定体系结构(arm64)在Xcode中设置Preprocessor Macro.我怎样才能做到这一点?

此处在Stackoverflow上存在类似的问题: Xcode 6:每个建筑. 但就我而言,Xcode 7只是不允许我选择架构.在Xcode版本7.1.17.3.1上进行了尝试,结果相同:Xcode提供的唯一体系结构选项是"*"(请参见下图). 预处理器设置部分

以防万一,这是我的体系结构"设置: 架构设置"部分

为了让您更多地了解为什么我实际上需要这个: 我使用3rd-party C库,该库依赖于一个标志集来告知它是否在32位或64位平台上运行. 库的集成指南中的注释:在构建64位体系结构时,必须在Xcode的预处理器宏部分中添加_64BIT宏."

这就是我尝试过的:

  • 找到一种方法来设置Xcode UI中特定于体系结构的宏(如上所述)
  • 通过将GCC_PREPROCESSOR_DEFINITIONS [arch = *]替换为GCC_PREPROCESSOR_DEFINITIONS [arch = arm64]手动修改.pbxproj文件(未达到预期的效果)

您是否有任何想法,我的Xcode设置有什么问题,为什么它不显示Preprocessor部分中的体系结构选项?还是在我的情况下还有其他方法可以配置宏?

解决方案

最后我已经弄清楚了.

已实现的结果:_64BIT宏将在预处理过程中添加到每个(至少今天都知道)64位环境中,而不管它是64位设备的模拟器还是真正的64位环境.位设备.

解决方案是如下手动编辑.pbxproj文件:

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

这是debug-config:

  • 第一部分定义了将应用于所有体系结构的默认宏;
  • 第二个和第三个定义自定义宏,这些宏只能应用于特定的体系结构.

然后,您手动完成的更改将在预处理器设置"编辑器中可见. 确实看起来像是Xcode的编辑器中的错误.

您可能会注意到,在发布问题之前,我已经尝试过这种方法,但是我误解了尝试的结果.事实是,我已经在模拟器上测试了我的应用,并且实际设备和相应模拟器上的体系结构有所不同.我已经将宏配置为包含在arm64体系结构中,但是模拟器的实际体系结构是x86_64.

作为进一步参考,文章介绍了每个架构实际上发生了:

  • arm7:用于支持iOS 7最早的设备
  • arm7s:用于iPhone 5和5C
  • arm64:对于iPhone 5S中的64位ARM处理器[,我相信对于更新的iPhone ]
  • i386:对于32位模拟器
  • x86_64:用于64位模拟器

对于i386和x86_64,此处暗示的是模拟设备的位",而不是Mac的.

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?

解决方案

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.

这篇关于Xcode 7:为每个体系结构设置预处理器宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆