Xcode 9 引发涉及“需要"的错误 [英] Xcode 9 throws errors involving 'require'

查看:25
本文介绍了Xcode 9 引发涉及“需要"的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级代码以在 Xcode 9 下构建时,我在使用 requirerequire_noerr 的代码中看到编译错误:

When upgrading code to build under Xcode 9, I see compile errors in code using require and require_noerr:

    require(length > offsetof(struct blob, cert), outLabel);

第一个错误是:错误:函数'require'的隐式声明在C99中无效

我也收到很多错误:使用未声明的标识符'outLabel'.这是在 RRTransactionVerifier.m 中,它是 Apple 处理收据验证的代码.

I also get a lot of error: use of undeclared identifier 'outLabel'. This is in RRTransactionVerifier.m which is Apple code for dealing with receipt validation.

如何修复这些错误?

推荐答案

requirerequire_noerr 是曾经在 AssertMacros.h 中定义的宏.从 Xcode 9 开始,这些宏发生了变化.

require and require_noerr are macros that used to be defined in AssertMacros.h. As of Xcode 9 these macros have changed.

原因记录在该头文件中:

The reasons are documented in that header file:

自古以来,Mac OS X 已经定义了其中大部分的版本没有 __ 前缀的宏,这可能会与类似命名的冲突用户代码中的函数或宏,包括 Boost 中的新功能和 C++ 标准库.

For time immemorial, Mac OS X has defined version of most of these macros without the __ prefix, which could collide with similarly named functions or macros in user code, including new functionality in Boost and the C++ standard library.

macOS High Sierra 和 iOS 11 现在将要求客户端迁移到上面定义的新宏.

macOS High Sierra and iOS 11 will now require that clients move to the new macros as defined above.

如果您想启用宏以供您自己使用项目,您可以定义__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 宏通过 Xcode 构建配置.请参阅添加构建配置 (xcconfig) 文件"在 Xcode 帮助中.

If you would like to enable the macros for use within your own project, you can define the __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES macro via an Xcode Build Configuration. See "Add a build configuration (xcconfig) file" in Xcode Help.

所以要解决这个问题,您可以设置定义,或更改您的代码以使用新的宏.require 现在是 __Requirerequire_noerr 现在是 __Require_noErr,依此类推.他们在头文件中提供了一个关于如何通过脚本更改代码的脚本:

So to fix the issue you can set that define, or change your code to use the new macros. require is now __Require, require_noerr is now __Require_noErr, and so on. They provide a script in the header file on how to change your code via a script:

在脚本第一行的末尾添加一个反斜杠,否则终端会将命令分成两部分.

Added one backslash in the end of the script's first line, otherwise Terminal would break the command into two.

/*
To aid users of these macros in converting their sources, the following tops script 
will convert usages of the old macros into the new equivalents.  To do so, in Terminal 
go into the directory containing the sources to be converted and run this command.

find . -name '*.[c|cc|cp|cpp|m|mm|h]' -print0 |  xargs -0 tops \
-verbose \
      replace "check(<b args>)" with "__Check(<args>)" \
      replace "check_noerr(<b args>)" with "__Check_noErr(<args>)" \
      replace "check_noerr_string(<b args>)" with "__Check_noErr_String(<args>)" \
      replace "check_string(<b args>)" with "__Check_String(<args>)" \
      replace "require(<b args>)" with "__Require(<args>)" \
      replace "require_action(<b args>)" with "__Require_Action(<args>)" \
      replace "require_action_string(<b args>)" with "__Require_Action_String(<args>)" \
      replace "require_noerr(<b args>)" with "__Require_noErr(<args>)" \
      replace "require_noerr_action(<b args>)" with "__Require_noErr_Action(<args>)" \
      replace "require_noerr_action_string(<b args>)" with "__Require_noErr_Action_String(<args>)" \
      replace "require_noerr_string(<b args>)" with "__Require_noErr_String(<args>)" \
      replace "require_string(<b args>)" with "__Require_String(<args>)" \
      replace "verify(<b args>)" with "__Verify(<args>)" \
      replace "verify_action(<b args>)" with "__Verify_Action(<args>)" \
      replace "verify_noerr(<b args>)" with "__Verify_noErr(<args>)" \
      replace "verify_noerr_action(<b args>)" with "__Verify_noErr_Action(<args>)" \
      replace "verify_noerr_string(<b args>)" with "__Verify_noErr_String(<args>)" \
      replace "verify_string(<b args>)" with "__Verify_String(<args>)" \
      replace "ncheck(<b args>)" with "__nCheck(<args>)" \
      replace "ncheck_string(<b args>)" with "__nCheck_String(<args>)" \
      replace "nrequire(<b args>)" with "__nRequire(<args>)" \
      replace "nrequire_action(<b args>)" with "__nRequire_Action(<args>)" \
      replace "nrequire_action_quiet(<b args>)" with "__nRequire_Action_Quiet(<args>)" \
      replace "nrequire_action_string(<b args>)" with "__nRequire_Action_String(<args>)" \
      replace "nrequire_quiet(<b args>)" with "__nRequire_Quiet(<args>)" \
      replace "nrequire_string(<b args>)" with "__nRequire_String(<args>)" \
      replace "nverify(<b args>)" with "__nVerify(<args>)" \
      replace "nverify_string(<b args>)" with "__nVerify_String(<args>)" \
      replace "require_action_quiet(<b args>)" with "__Require_Action_Quiet(<args>)" \
      replace "require_noerr_action_quiet(<b args>)" with "__Require_noErr_Action_Quiet(<args>)" \
      replace "require_noerr_quiet(<b args>)" with "__Require_noErr_Quiet(<args>)" \
      replace "require_quiet(<b args>)" with "__Require_Quiet(<args>)" \
      replace "check_compile_time(<b args>)" with "__Check_Compile_Time(<args>)" \
      replace "debug_string(<b args>)" with "__Debug_String(<args>)"
*/

这篇关于Xcode 9 引发涉及“需要"的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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