gpt4 book ai didi

Xcode 9 抛出涉及 'require' 的错误

转载 作者:行者123 更新时间:2023-12-02 08:02:11 26 4
gpt4 key购买 nike

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

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

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

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

如何修复这些错误?

最佳答案

requirerequire_noerr 是过去在 AssertMacros.h 中定义的宏。从 Xcode 9 开始,这些宏已更改。

原因记录在该头文件中:

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 and iOS 11 will now require that clients move to the new macros as defined above.

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,依此类推。他们在头文件中提供了一个脚本,介绍如何通过脚本更改代码:

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

/*
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 抛出涉及 'require' 的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46221364/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com