今天在引入一个第三方的拍照选择照片的库时,编译报错。
Undefined symbolsforarchitecture x86_64:"_ALAssetPropertyAssetURL", referenced from: -[TZImageManager getAssetIdentifier:]inTZImageManager.o"_ALAssetPropertyDuration", referenced from: ___90-[TZImageManager getAssetsFromFetchResult:allowPickingVideo:allowPickingImage:completion:]_block_invoke139inTZImageManager.o ___97-[TZImageManager getAssetFromFetchResult:atIndex:allowPickingVideo:allowPickingImage:completion:]_block_invokeinTZImageManager.o"_ALAssetPropertyType", referenced from: ___90-[TZImageManager getAssetsFromFetchResult:allowPickingVideo:allowPickingImage:completion:]_block_invoke139inTZImageManager.o ___97-[TZImageManager getAssetFromFetchResult:atIndex:allowPickingVideo:allowPickingImage:completion:]_block_invokeinTZImageManager.o"_ALAssetPropertyURLs", referenced from: -[TZImageManager getVideoWithAsset:completion:]inTZImageManager.o -[TZImageManager isAssetsArray:containAsset:]inTZImageManager.o"_ALAssetTypeVideo", referenced from: ___90-[TZImageManager getAssetsFromFetchResult:allowPickingVideo:allowPickingImage:completion:]_block_invoke139inTZImageManager.o ___97-[TZImageManager getAssetFromFetchResult:atIndex:allowPickingVideo:allowPickingImage:completion:]_block_invokeinTZImageManager.o"_ALAssetsGroupPropertyName", referenced from: ___66-[TZImageManager getCameraRollAlbum:allowPickingImage:completion:]_block_invokeinTZImageManager.o ___60-[TZImageManager getAllAlbums:allowPickingImage:completion:]_block_invokeinTZImageManager.o"_OBJC_CLASS_$_ALAsset", referenced from: objc-class-refinTZImageManager.o"_OBJC_CLASS_$_ALAssetsFilter", referenced from: objc-class-refinTZImageManager.o"_OBJC_CLASS_$_ALAssetsGroup", referenced from: objc-class-refinTZImageManager.o"_OBJC_CLASS_$_ALAssetsLibrary", referenced from: objc-class-refinTZImageManager.o"_OBJC_CLASS_$_PHAsset", referenced from: objc-class-refinTZImageManager.o"_OBJC_CLASS_$_PHAssetCollection", referenced from: objc-class-refinTZImageManager.o"_OBJC_CLASS_$_PHAssetCreationRequest", referenced from: objc-class-refinTZImageManager.o"_OBJC_CLASS_$_PHAssetResourceCreationOptions", referenced from: objc-class-refinTZImageManager.o"_OBJC_CLASS_$_PHCachingImageManager", referenced from: objc-class-refinTZImageManager.o"_OBJC_CLASS_$_PHFetchOptions", referenced from: objc-class-refinTZImageManager.o"_OBJC_CLASS_$_PHFetchResult", referenced from: objc-class-refinTZImageManager.o"_OBJC_CLASS_$_PHImageManager", referenced from: objc-class-refinTZAssetCell.o objc-class-refinTZImageManager.o"_OBJC_CLASS_$_PHImageRequestOptions", referenced from: objc-class-refinTZImageManager.o"_OBJC_CLASS_$_PHPhotoLibrary", referenced from: objc-class-refinTZImageManager.o"_OBJC_CLASS_$_PHVideoRequestOptions", referenced from: objc-class-refinTZImageManager.o"_PHImageCancelledKey", referenced from: ___58-[TZImageManager getPhotoWithAsset:photoWidth:completion:]_block_invokeinTZImageManager.o ___55-[TZImageManager getOriginalPhotoWithAsset:completion:]_block_invokeinTZImageManager.o"_PHImageErrorKey", referenced from: ___58-[TZImageManager getPhotoWithAsset:photoWidth:completion:]_block_invokeinTZImageManager.o ___55-[TZImageManager getOriginalPhotoWithAsset:completion:]_block_invokeinTZImageManager.o"_PHImageManagerMaximumSize", referenced from: -[TZImageManager getOriginalPhotoWithAsset:completion:]inTZImageManager.o"_PHImageResultIsDegradedKey", referenced from: ___58-[TZImageManager getPhotoWithAsset:photoWidth:completion:]_block_invokeinTZImageManager.o ___58-[TZImageManager getPhotoWithAsset:photoWidth:completion:]_block_invoke_2inTZImageManager.o"_PHImageResultIsInCloudKey", referenced from: ___58-[TZImageManager getPhotoWithAsset:photoWidth:completion:]_block_invokeinTZImageManager.old: symbol(s) not foundforarchitecture x86_64clang: error: linkercommandfailed withexitcode1(use -v to see invocation)
经过几个小时的查资料,和尝试,基本上确定了是由于部分依赖的框架没有导入(天知道为什么会没有导入,我在另一个项目里面直接拖进去就可以编译的,坑爹的xcode)。
于是我仔细看了下报错的内容,都是指向TZImageManager,于是我到对应的.m文件里面,发现它引用了系统的AssetsLibrary框架:
屏幕快照 2016-07-01 16.41.07.png
我尝试手动导入这个框架:
屏幕快照 2016-07-01 16.45.05.png
编译一下,原来报27个错,现在只有17个了,看来有效果。于是我继续找还缺少了什么框架。现在的报错如下:
Undefined symbolsforarchitecture x86_64:"_OBJC_CLASS_$_PHAsset", referenced from: objc-class-refinTZImageManager.o"_OBJC_CLASS_$_PHAssetCollection", referenced from: objc-class-refinTZImageManager.o"_OBJC_CLASS_$_PHAssetCreationRequest", referenced from: objc-class-refinTZImageManager.o"_OBJC_CLASS_$_PHAssetResourceCreationOptions", referenced from: objc-class-refinTZImageManager.o"_OBJC_CLASS_$_PHCachingImageManager", referenced from: objc-class-refinTZImageManager.o"_OBJC_CLASS_$_PHFetchOptions", referenced from: objc-class-refinTZImageManager.o"_OBJC_CLASS_$_PHFetchResult", referenced from: objc-class-refinTZImageManager.o"_OBJC_CLASS_$_PHImageManager", referenced from: objc-class-refinTZAssetCell.o objc-class-refinTZImageManager.o"_OBJC_CLASS_$_PHImageRequestOptions", referenced from: objc-class-refinTZImageManager.o"_OBJC_CLASS_$_PHPhotoLibrary", referenced from: objc-class-refinTZImageManager.o"_OBJC_CLASS_$_PHVideoRequestOptions", referenced from: objc-class-refinTZImageManager.o"_PHImageCancelledKey", referenced from: ___58-[TZImageManager getPhotoWithAsset:photoWidth:completion:]_block_invokeinTZImageManager.o ___55-[TZImageManager getOriginalPhotoWithAsset:completion:]_block_invokeinTZImageManager.o"_PHImageErrorKey", referenced from: ___58-[TZImageManager getPhotoWithAsset:photoWidth:completion:]_block_invokeinTZImageManager.o ___55-[TZImageManager getOriginalPhotoWithAsset:completion:]_block_invokeinTZImageManager.o"_PHImageManagerMaximumSize", referenced from: -[TZImageManager getOriginalPhotoWithAsset:completion:]inTZImageManager.o"_PHImageResultIsDegradedKey", referenced from: ___58-[TZImageManager getPhotoWithAsset:photoWidth:completion:]_block_invokeinTZImageManager.o ___58-[TZImageManager getPhotoWithAsset:photoWidth:completion:]_block_invoke_2inTZImageManager.o"_PHImageResultIsInCloudKey", referenced from: ___58-[TZImageManager getPhotoWithAsset:photoWidth:completion:]_block_invokeinTZImageManager.old: symbol(s) not foundforarchitecture x86_64clang: error: linkercommandfailed withexitcode1(use -v to see invocation)
当时在看这个报错的时候,一头雾水,PHxxx的库根本找不到,于是在.m里面找,半天之后猜是不是Photos框架,导入了之后编译成功!
猜得很艰辛啊。
现在写这个文章的时候,突然发现对应的TZImageManager.h文件里果然导入了Photos框架……
屏幕快照 2016-07-01 16.53.18.png
猜得那么辛苦,原来.h里面就有答案,醉了。
解决这个问题花了一个下午的时间,写一篇文章做个备份,免得下次又被坑。
文/Javen_01(简书作者)
原文链接:http://www.jianshu.com/p/d91f270f3763
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。