我可以使用什么预定义的宏来检测 Clang 中的目标架构? [英] What predefined macro can I use to detect the target architecture in Clang?

查看:22
本文介绍了我可以使用什么预定义的宏来检测 Clang 中的目标架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据目标架构是否是例如编写代码armv7、armv7s 或 arm64.

I would like to write code depending on whether the target architecture is e.g. armv7, armv7s, or arm64.

我不能使用的原因 sysctlbyname 是这将在运行时为我提供底层架构,但是当 arm64 例如模拟armv7,sysctl(貌似)还是报arm64.

The reason that I can't use sysctlbyname is that this would give me the underlying architecture at runtime, but when arm64 e.g. simulates armv7, sysctl (seemingly) still reports arm64.

推荐答案

clang --target=... -mcpu=... -E - -dM </dev/null will输出所有预定义的预处理器宏(gcc 也类似)

clang --target=... -mcpu=... -E - -dM </dev/null will output all the pre-defined preprocessor macros (similar works for gcc, too)

我没有看到提供答案的单个宏,但您可能可以使用 __ARM_ARCHdefined(__ARM_ARCH_*) 的某种组合.

I don't see single macro that provides the answer, but you can probably use some combination of __ARM_ARCH and defined(__ARM_ARCH_*).

这篇关于我可以使用什么预定义的宏来检测 Clang 中的目标架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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