Xcode 报错及警告消除

本文将详细解析在iOS开发过程中遇到的未知类问题及解决方法,包括如何处理编译期间未知类警告、运行时崩溃问题、以及链接STL错误。同时提供了解决这些问题的具体步骤和注意事项,帮助开发者更高效地解决问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

文/简书坤(简书作者)
原文链接:http://www.jianshu.com/p/11bc11a00f7f
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。

一.Unknown class XXX in Interface Builder file

1.错误出现后的现象:

(1)例如第一次是自定义的 CornerButton 文件没有找到 导致所有界面中用到 这个试图的 button 都没能正确的变为圆角,但是编译不会出错 (打印信息1)


打印信息1

(2)再次出现是在 一个 XXXViewController 导致的结果是 编译不会报错,但是当点击到跳转该界面是会 崩溃,并且报错信息为 一个动态库的错误 “libc++abi.dylib: terminating with uncaught exception of type NSException”(如图 崩溃信息1)<勘误1>


崩溃信息1

2.解决办法

到 project -> targets -> build phasses -> compile Sources 中添加所报的 unknown class... 例如 添加 CornerButton.m 文件(如图 解决办法1)


解决办法1

补充:Undefined symbols for architecturei386:(或者x8_64:) 如果缺少类库,则在Link Binary With Libraries中加入该类库。

二.CGContextSetStrokeColorWithColor: invalid context 0x0.

1.报错名称 : CGContextSaveGState: invalid context 0x0.  CGContextDrawPath: invalid context 0x0.等。我这里编译时并没有报错也无警告,直到运行时才在控制台打印了一系列的<Error>信息 如下图(错误信息)


错误信息

出现这类错误的原因是没有在 view 的 -drawRect:  方法中对 layer 进行了不适当的操作 例如 UIBezierPath 的 - (void)setFill; - (void)setStroke; 方法  UIColor 的 - (void)setFill; - (void)setStroke;方法 等。

2.解决方法

(1).把有关于 view layer 层的操作单独封装到一个 view 类的 -drawRect: 方法中

(2).不要调用 相关的方法 ,官方一般都给了注释,com+单击 就可查看:如下图(官方给定的限制->drawing context)


官方给定的限制->drawing context



勘误:

1.并不是所有缺少 XXXViewController 都会在跳转的时候导致崩溃,但是如果 这个VC有关联的sb或者xib文件时一定会崩溃。如下图(勘误1)是 Unknown class ViewController1 in Interface Builder file 时,ViewController1 中的关联失效


勘误1

三.关于xib或者SB中的两个警告的问题(在兼容iOS6.0时出现)

3.1.1 警告及原因: Automatic Preferred Max Layout Width before iOS 8.0 (或者是:Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0  。具体警告应该和 XCode版本有关,我的是XCode7.1正式版的),警告出现在‘UILabel’的约束中,出现次警告的设置如下图



2个警告的示例

设置了行数为0时出现

3.1.2 解决办法:如下图设置



如图勾选并填写

解释:1.为什么会填入300? 这是因为我设置的 约束为 距离屏幕左右各为10的距离 然后考虑到,运行在iPhone4s 上 因此 设为 屏幕的宽320 减去 边距 10 ,10  

        2.Preferred Width(自动换行最大宽度) 设置为300 会不会影响在 6和6p上的换行?不会的 运行效果如下图,只有在到达约束的限制距离时 才会启动换行



6p上的表现



4s上的表现

3.2 'Jusitfied or Natural text alignment before iOS 7.0'

出现的警告原因已经很明确了,对 ‘UILabel’ 的 textAligment 的设置不兼容 iOS 7.0 之前的系统,出现的原因如下图:



不兼容iOS7.0之前的对齐方式如箭头所指

解决方法:十分简单 ,根据需求选择图中圈中的任意一种对齐方式即可(创建的时候一定要仔细要不你就要和我一样该一中午的sb和xib文件了)

四.集成了某些第三方后突然出现200+的警告(如下)

warning: /Users/qiandong/Library/Developer/Xcode/DerivedData/ModuleCache/OJZ27JBFTDXF/ObjectiveC-1AJ1UYHO2U5H0.pcm: No object file for requested architecture

warning: Could not resolve external type c:objc(cs)NSObject
warning: Could not resolve external type c:objc(cs)NSString
warning: Could not resolve external type c:objc(cs)NSMutableDictionary

等等。。大量的相似警告

解决办法:如下图设置即可



设置后清理工程在运行就没了

(具体原因:说法好多,也不知道该怎么解释了,可以自己 google )

四."std::__1::__vector_base_common::__throw_length_error() const", referenced from: 等一大堆类此错误

1.报错形式如下

Undefined symbols for architecture x86_64:  "std::__1::__vector_base_common::__throw_length_error() const", referenced from:      cv::SparseMat::resizeHashTab(unsigned long) in opencv2(matrix.o)      std::__1::vector>::__append(unsigned long) in opencv2(matrix.o)      std::__1::vector>::__append(unsigned long) in opencv2(matrix.o)      std::__1::enable_if<(__is_forward_iterator::value) && (is_constructible::reference>::value), void>::type std::__1::vector>::assign(cv::cuda::GpuMat*, cv::cuda::GpuMat*) in opencv2(matrix.o)      std::__1::vector>, std::__1::allocator> > >::__append(unsigned long) in opencv2(matrix.o)      std::__1::vector>, std::__1::allocator> > >::__swap_out_circular_buffer(std::__1::__split_buffer>, std::__1::allocator> >&>&) in opencv2(matrix.o)      std::__1::vector>::__append(unsigned long) in opencv2(matrix.o)      ...  "std::__1::__basic_string_common::__throw_length_error() const", referenced from:      std::__1::basic_stringbuf, std::__1::allocator>::str() const in opencv2(ocl.o)  "std::__1::locale::use_facet(std::__1::locale::id&) const", referenced from:      std::__1::basic_ostream>& std::__1::__put_character_sequence>(std::__1::basic_ostream>&, char const*, unsigned long) in opencv2(ocl.o)  "std::__1::ios_base::getloc() const", referenced from:      std::__1::basic_ostream>& std::__1::__put_character_sequence>(std::__1::basic_ostream>&, char const*, unsigned long) in opencv2(ocl.o)  "std::__1::basic_string, std::__1::allocator>::resize(unsigned long, char)", referenced from:      std::__1::basic_stringbuf, std::__1::allocator>::str(std::__1::basic_string, std::__1::allocator> const&) in opencv2(ocl.o)      std::__1::basic_stringbuf, std::__1::allocator>::overflow(int) in opencv2(ocl.o)  "std::__1::basic_string, std::__1::allocator>::push_back(char)", referenced from:      std::__1::basic_stringbuf, std::__1::allocator>::overflow(int) in opencv2(ocl.o)  "std::__1::basic_string, std::__1::allocator>::~basic_string()", referenced from:      cv::ocl::kernelToStr(cv::_InputArray const&, int, char const*) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      ...  "std::__1::basic_string, std::__1::allocator>::operator=(std::__1::basic_string, std::__1::allocator> const&)", referenced from:      std::__1::basic_stringbuf, std::__1::allocator>::str(std::__1::basic_string, std::__1::allocator> const&) in opencv2(ocl.o)  "std::__1::basic_ostream>::sentry::sentry(std::__1::basic_ostream>&)", referenced from:      std::__1::basic_ostream>& std::__1::__put_character_sequence>(std::__1::basic_ostream>&, char const*, unsigned long) in opencv2(ocl.o)  "std::__1::basic_ostream>::sentry::~sentry()", referenced from:      std::__1::basic_ostream>& std::__1::__put_character_sequence>(std::__1::basic_ostream>&, char const*, unsigned long) in opencv2(ocl.o)  "std::__1::basic_ostream>::~basic_ostream()", referenced from:      construction vtable for std::__1::basic_ostream>-in-std::__1::basic_ostringstream, std::__1::allocator> in opencv2(ocl.o)  "std::__1::basic_ostream>::~basic_ostream()", referenced from:      construction vtable for std::__1::basic_ostream>-in-std::__1::basic_ostringstream, std::__1::allocator> in opencv2(ocl.o)  "std::__1::basic_ostream>::~basic_ostream()", referenced from:      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      ...  "std::__1::basic_ostream>::operator<<(double)", referenced from:      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)  "std::__1::basic_ostream>::operator<<(float)", referenced from:      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)  "std::__1::basic_ostream>::operator<<(int)", referenced from:      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      ...  "std::__1::basic_ostream>::operator<<(short)", referenced from:      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)  "std::__1::basic_ostream>::operator<<(unsigned short)", referenced from:      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)  "std::__1::basic_streambuf>::sync()", referenced from:      vtable for std::__1::basic_stringbuf, std::__1::allocator> in opencv2(ocl.o)  "std::__1::basic_streambuf>::imbue(std::__1::locale const&)", referenced from:      vtable for std::__1::basic_stringbuf, std::__1::allocator> in opencv2(ocl.o)  "std::__1::basic_streambuf>::uflow()", referenced from:      vtable for std::__1::basic_stringbuf, std::__1::allocator> in opencv2(ocl.o)  "std::__1::basic_streambuf>::setbuf(char*, long)", referenced from:      vtable for std::__1::basic_stringbuf, std::__1::allocator> in opencv2(ocl.o)  "std::__1::basic_streambuf>::xsgetn(char*, long)", referenced from:      vtable for std::__1::basic_stringbuf, std::__1::allocator> in opencv2(ocl.o)  "std::__1::basic_streambuf>::xsputn(char const*, long)", referenced from:      vtable for std::__1::basic_stringbuf, std::__1::allocator> in opencv2(ocl.o)  "std::__1::basic_streambuf>::showmanyc()", referenced from:      vtable for std::__1::basic_stringbuf, std::__1::allocator> in opencv2(ocl.o)  "std::__1::basic_streambuf>::basic_streambuf()", referenced from:      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      ...  "std::__1::basic_streambuf>::~basic_streambuf()", referenced from:      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)      std::__1::basic_string, std::__1::allocator > cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)ld:

symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation

有这么多的link STL的错误。其实,就是你编译静态库的时候使用不同版本的标准库,C++ Standard Library

类似情况会出现在 c++ 混编的情况下,如下设置可消除报错


<think>好的,我现在需要帮用户解决Xcode报错“Library 'ByteDanceAdapter' not found”的问题。首先,我得回忆一下常见的Xcode库文件缺失错误的原因,可能包括路径问题、链接设置不正确、CocoaPods或Swift Package Manager的依赖未正确安装等。 用户提到的ByteDanceAdapter,听起来像是第三方库,可能来自字节跳动的广告SDK或者其他相关服务。首先应该考虑依赖管理工具是否配置正确。比如,如果项目使用CocoaPods,可能需要检查Podfile里是否有添加该库,然后执行pod install。如果是手动集成,可能需要检查库文件是否被正确拖入项目,并在Build Phases里添加了链接。 接下来,可能的解决步骤包括:1. 确认依赖管理工具是否正确安装和配置;2. 清理并重新构建项目;3. 检查库的路径是否在Framework Search Paths里设置正确;4. 确保库的目标成员资格正确,即库是否被添加到目标的依赖项中;5. 查看是否有版本冲突或兼容性问题。 另外,用户可能对CocoaPods或SPM不太熟悉,需要给出具体的命令行操作,比如pod repo update,pod install等。同时,需要提醒用户检查终端输出是否有其他错误信息,这些可能帮助定位问题。最后,如果以上步骤都无效,建议用户查看官方文档或联系库的提供方获取支持。</think>当Xcode报错`Library 'ByteDanceAdapter' not found`时,通常是由于第三方库集成问题导致。以下是分步解决方案: **1. 检查依赖管理工具** - 若使用CocoaPods: ```bash # 确保Podfile包含该库(示例) pod 'ByteDanceAdapter', '~> 4.3.0' # 更新并安装 pod repo update pod install ``` 完成后必须用`.xcworkspace`打开项目 - 若手动集成: - 检查`ByteDanceAdapter.framework`是否存在于项目目录 - 右键`.xcodeproj`选择`Add Files to...`重新添加 **2. 配置Build Settings** 在Target的Build Settings中: - 确认`Library Search Paths`包含框架路径 ```bash $(PROJECT_DIR)/Pods/ByteDanceAdapter # 示例路径 ``` - 检查`Other Linker Flags`是否包含`-ObjC` **3. 验证Framework引用** 在Target的`Build Phases`中: - `Link Binary With Libraries`需包含`ByteDanceAdapter.framework` - 在`Embed Frameworks`阶段添加该框架(如需要) **4. 清理项目** 使用快捷键`Command+Shift+K`彻底清理后重新编译 **5. 检查架构兼容性** 在`Build Settings`中: - 确保`Excluded Architectures`未错误排除arm64 - 验证`VALID_ARCHS`包含当前设备架构 **6. 版本兼容性验证** 检查是否满足最低系统版本要求: - 在`Info.plist`中`iOS Deployment Target`需匹配库要求 - 对比Xcode版本与库文档要求 **进阶排查:** - 执行`pod deintegrate`后重新`pod install` - 检查终端警告信息,可能存在: ```log [!] The 'Pods-YourTarget' target has transitive dependencies... ``` 这类警告可能暗示更深层次的依赖冲突 **常见陷阱:** 1. 混合使用Swift Package Manager和CocoaPods时路径冲突 2. 使用模拟器架构(x86_64)但库仅提供真机包(arm64) 3. 防火墙拦截导致依赖下载不完整 如问题仍未解决,建议: 1. 查看字节跳动广告SDK官方集成文档 2. 运行`pod env`检查CocoaPods环境 3. 在终端执行`xcodebuild -showBuildSettings`验证实际编译参数
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值