为什么 -mmacosx-version-min=10.10 不阻止使用标记为从 10.11 开始的函数?
Why isn't -mmacosx-version-min=10.10 preventing use of a function tagged as starting in 10.11?
根据我对可用性宏和-mmacosx-version-min
标志如何工作的理解,以下代码在面向OS X 10.10时应该无法编译:
#include <Availability.h>
#include <CoreFoundation/CoreFoundation.h>
#include <Security/Security.h>
#if !defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
#error
#endif
#if __MAC_OS_X_VERSION_MIN_REQUIRED < 101000
#error __MAC_OSX_VERSION_MIN_REQUIRED too low
#endif
#if __MAC_OS_X_VERSION_MIN_REQUIRED > 101000
#error __MAC_OSX_VERSION_MIN_REQUIRED too high
#endif
int main() {
size_t len = 0;
SSLContextRef x{};
auto status = SSLCopyRequestedPeerNameLength(x, &len);
return status != 0;
}
因为函数SSLCopyRequestedPeerNameLength
在 10.11 中被标记为在SecureTransport.h
中可用:
$ grep -C5 ^SSLCopyRequestedPeerNameLength /System/Library/Frameworks//Security.framework/Headers/SecureTransport.h
/*
* Server Only: obtain the hostname specified by the client in the ServerName extension (SNI)
*/
OSStatus
SSLCopyRequestedPeerNameLength (SSLContextRef ctx,
size_t *peerNameLen)
__OSX_AVAILABLE_STARTING(__MAC_10_11, __IPHONE_9_0);
然而,当我使用-mmacosx-version-min=10.10
在命令行上编译时,我根本没有收到任何警告,尽管-Wall -Werror -Wextra
:
$ clang++ -Wall -Werror -Wextra ./foo.cpp --std=c++11 -framework Security -mmacosx-version-min=10.10 --stdlib=libc++ ; echo $?
0
我是否需要提供一些其他定义或特定警告才能启用以确保我不会选择对高于 10.10 的 API 的依赖关系?我真的期望-mmacosx-version-min=10.10
会阻止使用标有更高版本号的 API。
我在这里误解了什么?
在此处在 macOS 10.13.6 上使用 XCode 10.0 (10A255(。
现在我可以回答我自己的问题,我将:您需要将-Wunguarded-availability
添加到编译标志中。只有这样,您才会收到警告/错误。
相关文章:
- 为什么 -mmacosx-version-min=10.10 不阻止使用标记为从 10.11 开始的函数?
- 如何以毫秒为单位获取开始时间和 now() 之间的毫秒差异(以 C++为单位?
- 如何在 c++ 中确定一条指令(以字节为单位)在哪里结束,另一条指令从哪里开始?
- 在C++中将字符串转换为双精度,而无需科学记数法
- 从头开始为应用程序创建 docker 映像是否有意义?
- 将文本文件读取到2D数组中,但数组开始为超过数组[39][]的任何内容输出胡言乱语
- 将大双精度转换为科学记数法以用作字符串?
- 从头开始为使用Qt的应用程序制作简约的构建文件
- 如何为一个类提供多个开始/结束代理
- 为什么C++向量大小从 4294967296 开始,而调试器将其读取为 0?
- 从头开始为多目录项目制作 Cmake
- 如何将SSCANF()设置为在字符串开始时忽略字符
- 寻找教程或基本信息,让我开始在C#中为初学者实现C/C++API
- 新的类型安全枚举是否定义为从 0 开始
- Rand从一个最大值为75的数字(36)开始时是如何工作的
- 如何从1970年1月1日(C++)开始获取当前系统时间(以毫秒为单位)
- 如何开始学习用C++为XBOX 360 KINECT编写用于开发windows应用程序的程序的基础知识
- 在科学记数法中将双精度转换为字符串的速度比在 c++ 中将 sprintf 转换得更快
- 如何开始为linux编写防火墙
- 在C#中为windows API编写COM服务器,从何开始