美文网首页
解决编译错误"function does not return

解决编译错误"function does not return

作者: 超哥__ | 来源:发表于2025-04-20 15:45 被阅读0次

这次遇到的问题是xcode15+ios17.sdk编译没问题,但换成低版本clang(clang<=13)会报如下错误:
In file included from /Users/apple/Documents/xcodetest/aa/aa/main.m:8:
In file included from /Applications/Xcode15.2.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.2.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:13:
In file included from /Applications/Xcode15.2.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.2.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSBundle.h:6:
/Applications/Xcode15.2.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.2.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSString.h:378:81: error: function does not return string type

  • (nullable instancetype)initWithUTF8String:(const char *)nullTerminatedCString NS_FORMAT_ARGUMENT(1);

简单搜了下很多人都遇到过此问题,经过跟踪发现ios17.sdk中很多地方用到了NS_FORMAT_ARGUMENT,首次触发报错在NSString.h中,而低版本xcode对应的低版本sdk中没有用该宏
,而NS_FORMAT_ARGUMENT用到了format_arg,经过测试可以发现clang<=13是不支持format_arg的。所以以上报错与clang/iphone_sdk都有关。那么有没有办法解决呢?这里提供一个方案:

  1. 在include 第一个oc头文件之前#define format_arg(n)
  2. Build Settings -> Enable Modules -> No
    编译成功

相关文章

网友评论

      本文标题:解决编译错误"function does not return

      本文链接:https://www.haomeiwen.com/subject/fcmsdjtx.html