关于xcode编译链接三方库问题--build system tpye

一、场景

由于苹果系统不断升级更新,作为开发者,使用的系统环境和开发工具也要跟上步伐,在去年的某一天我将MAC系统和 xcode工具都进行了升级,因为上架引用需要,具体可以参考上一篇记录:

https://blog.csdn.net/yangwubolwg/article/details/109049512

当时升完级之后,遗留了一个问题,就是pod工具无法使用了, 我记得应该是MAC 系统版本升级之后,原先安装的工具版本已经用不了,所以需要升级ruby环境,以及对应工具,但是当时并没有找到

合适的解决方案,而是留下了未解之问题。

hongbodeMac-mini:debug hongboni$ sudo gem install -n /usr/local/bin cocoapods

Fetching ffi-1.14.2.gem

Fetching cocoapods-core-1.10.1.gem

Fetching cocoapods-1.10.1.gem

Building native extensions. This could take a while...

ERROR: Error installing cocoapods:

ERROR: Failed to build gem native extension.

 

二、问题分析

光阴流转,岁月如梭,时间不知不觉过了多少日月,又有语音识别集成的功能需要开发了,在集成别人SDK 的过程中发现自己的项目有时候会忽然包一个莫名的pod 引用三方库里面的类找不到定义的问题:

Undefined symbols for architecture arm64:

"_OBJC_CLASS_$_YYAnimatedImageView", referenced from:

objc-class-ref in YHBrowserImageView.o

ld: symbol(s) not found for architecture arm64

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

 

当时刚看到这个问题的时候真的是一脸懵逼,莫名其妙,摸不着头发。这个图片预览的库多年来从未动过,为啥会突然报这种问题,为什么其他地方就没有问题。于是想了想它有何特别之处,唉, 它好像

不是本地代码编译的,而是通过pod 引用过来的耶,这个外来汉是不是因为上次升级系统之后,pod 不可用造成的呢???

于是,开始将注意力转移到恢复正常的pod 使用上来,当时想想,出来混,迟早要还的。果然还是要面对这个问题,最终在一遍又一遍地搜索解决方案之后,找到了如下方法:

https://blog.csdn.net/a892445213/article/details/104837529

Error: gem native extension error while installing cocoapods

Answer: Follow below 3 Steps issue will be fixed.

Step 1: Open XCode go to below path

XCode > Preferences > Locations > Command Line Tools (select-Xcode)

Step 2: Open Terminal- Paste the below Command

curl -L https://get.rvm.io | bash -s stable

Reopen Terminal -Paste the below Commands

Note: It will take 3-5 minutes

rvm install ruby-2.6

rvm use ruby-2.6.3

rvm --default use 2.6.3

Step3:

Open Terminal- Type below Command

sudo gem install cocoapods

Now gem native extension error while installing cocoapods will not come

Issue resolved.

在更新安装ruby之前先要执行此命令:

rvm autolibs read-only

rvm install ruby-2.6

 

 

No binary rubies available for: osx/10.15/x86_64/ruby-2.6.6.

Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.

Checking requirements for osx.

Missing required packages: autoconf automake libtool pkg-config coreutils libksba zlib

Certificates bundle '/usr/local/etc/openssl@1.1/cert.pem' is already up to date.

Requirements installation successful.

Installing Ruby from source to: /Users/hongboni/.rvm/rubies/ruby-2.6.6, this may take a while depending on your cpu(s)...

ruby-2.6.6 - #downloading ruby-2.6.6, this may take a while depending on your connection...

** Resuming transfer from byte position 1221096

% Total % Received % Xferd Average Speed Time Time Time Current

Dload Upload Total Spent Left Speed

100 12.3M 100 12.3M 0 0 583k 0 0:00:21 0:00:21 --:--:-- 647k

ruby-2.6.6 - #extracting ruby-2.6.6 to /Users/hongboni/.rvm/src/ruby-2.6.6.....

ruby-2.6.6 - #configuring.......................................................................

ruby-2.6.6 - #post-configuration.

ruby-2.6.6 - #compiling.....................................................................

ruby-2.6.6 - #installing...........

ruby-2.6.6 - #making binaries executable..

ruby-2.6.6 - #downloading rubygems-3.0.9

% Total % Received % Xferd Average Speed Time Time Time Current

Dload Upload Total Spent Left Speed

100 865k 100 865k 0 0 961k 0 --:--:-- --:--:-- --:--:-- 960k

No checksum for downloaded archive, recording checksum in user configuration.

ruby-2.6.6 - #extracting rubygems-3.0.9.....

ruby-2.6.6 - #removing old rubygems........

ruby-2.6.6 - #installing rubygems-3.0.9................................................................

ruby-2.6.6 - #gemset created /Users/hongboni/.rvm/gems/ruby-2.6.6@global

ruby-2.6.6 - #importing gemset /Users/hongboni/.rvm/gemsets/global.gems................................................................

ruby-2.6.6 - #generating global wrappers........

ruby-2.6.6 - #gemset created /Users/hongboni/.rvm/gems/ruby-2.6.6

ruby-2.6.6 - #importing gemsetfile /Users/hongboni/.rvm/gemsets/default.gems evaluated to empty gem list

ruby-2.6.6 - #generating default wrappers........

ruby-2.6.6 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).

Install of ruby-2.6.6 - #complete

Ruby was built without documentation, to build it run: rvm docs generate-ri

 

如此操作一番,果然pod 又重获新生了。 但是之前遇到的编译问题仍然存在,后来才知道这个pod 引用一旦到了本地,不更新的话,和这个工具没有任何关系,在编译过程中。

由于这个问题还有时候出现,有时候重新下载一份新的代码编译时又不出现,所以就没有头绪了,然后就期望能够对比出差异,于是在xcode 工程文件的配置上疯狂对比,将编译正常的,和编译失败的两个工程。

将网上说的编译链接文件涉及的两个配置一个个对比,一个个同步修改,似乎始终没有任何反应,以至于自己都怀疑是否改对了项目文件,但是故意将项目中的源码改错,又确认发现编译的是这个项目。

 

由于pod 可以正常使用了,所以在此尝试将原先的pod文件以及引用还有xcworkspace 等文件删除,然后重新使用pod init , 再pod install 这种方式来构建编译工程,你还别说,竟然真的

编译通过了,所以那段时间就想是不是因为项目工程环境的某个自己不知道的地方被改变了造成的问题。于是想将就着用这种方式解决此问题算了。

但是当自己用这种方式成功运行应用到手机,发现之前的图片预览功能失效了,一片黑。。。。, 自己的眼前也是一片黑。真是一波未平,一波又起。

在一阵查找原因未果之后,打算另外再寻找一个开源库,但是没有找到合适的,然后想起了直接先运行之前开源库的demo,结果发现功能也有问题,所以应该是兼容问题,后面想起了自己的手机

系统升级到了ios14 了,在github 一查,还真有人遇到了同样的问题,不过没有解决方案,最后几经周折,发现了处理过的开源库,急忙尝试,亲测有效,于是还兴高采烈地在github上分享给别人。

https://github.com/QiuYeHong90/YYImage/commit/f3c3d860466486c73015eaf473d574d3af2a64fc

 

 

解决完这个兼容问题之后,我又发现之前的工程目录,不使用pod 重新构建也能编译成功运行,但是在使用clean 之后,就再也不行了:

 

当时又懵逼了,太多的未知因素了,一次次挑战者自己的耐心,是继续查还是将就着过去算了,that to be the question.

这个问题已经花费了好多天的时间了,但是想找到真正原因,于是就接着百度接着搜,最终找到了一个和这个有点关联的文章:

https://cloud.tencent.com/developer/article/1405011

于是才将我引导到了关于xcode 的 build sytem type 这个设置上来,这个我之前从来没有注意过:

于是接着这个信息往下了解这个配置的作用,看到了如下两篇文章,虽然不明白,但是感觉我这个问题目前看到的原因就和这个相关了:

https://www.pianshen.com/article/9126124703/

https://blog.csdn.net/weixin_34107955/article/details/91369280

将xcode 工程配置的build sytem type 改为legacy 之后,使用clean ,编译链接也能正常了,至此我想问题的原因也要告一段落了,我也没有时间再继续查下去了,就这样吧。

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值