编译报错framework not found Metal for architecture armv7 问题

Ever since Apple introduced iOS SDK 8.0, apps referencing CoreVideo or OpenGLES may encounter the following linker error:

framework not found Metal for architecture armv7

This happens only when:

1.  The build target is a real device and not the Simulator.

2.  The linker flags include the “-ObjC” flag (this one is set by default in CocoaPods).

3.  The code was compiled with SDK 8.0, and used by an app compiled for an earlier SDK (using XCode < 6.0).

The Reason

The reason behind this, is actually a bug / bad design by Apple, which failed to preserve backward compatibility for non-Metal devices (namely: armv7 & armv7s).

Taking a look at CoreVideo.h reveals this:

#if COREVIDEO_SUPPORTS_METAL
#include <CoreVideo/CVMetalTexture.h>
#include <CoreVideo/CVMetalTextureCache.h>
#endif

HoweverCOREVIDEO_SUPPORTS_METAL is defined only as #if TARGET_OS_IPHONE

(which is not enough, since armv7/s devices do not support Metal).

The new “Link Frameworks Automatically” flag

In XCode 5, Apple introduced a new linker flag, named “Link Frameworks Automatically”, which defaults to “YES”. The purpose of this flag is to reduce the effort required by developers when adding a framework. Before the introduction of this flag, developers had to link their projects with system frameworks prior to using them. This flag allows them to simply use the frameworks.

After a thorough investigation, we found out that this works by the addition of a special load command in the output binary, called “LC_LINKER_OPTION”, which contains the framework that the binary links to. For example, when running:

otool -arch armv7 –l Appsee.framework/Appsee

We found out the following sections:

Load command 14
cmd LC_LINKER_OPTION
cmdsize 32
count 2
string #1 -framework
string #2 OpenGLES
Load command 15

cmd LC_LINKER_OPTION
cmdsize 32
count 2
string #1 -framework
string #2 Metal
Load command 16

As you can see, this will cause the linker to implicitly search for “Metal” when used.

The Solution

Until/if Apple addresses this issue, our solution was to disable the “Link Frameworks Automatically” flag when building the framework. This way, the load commands will not be included in the binary and it may be used for non-metal architectures. Nothing else should be affected, since this flag does not seem to work for frameworks referenced by our framework (i.e.: when an app links with Appsee, it would still need to reference the different frameworks which Appsee uses, whether the flag was on or off).

Happy linking!

 

The following posts helped us (thanks!) –

https://github.com/CocoaPods/CocoaPods/issues/2457
http://tonyarnold.com/2014/04/10/clean-up-your-projects-with-xcode-5.html
https://github.com/card-io/card.io-iOS-SDK/issues/66

大概意思就是说:

有三种情况会出现这个报错,第三种那个应该是苹果的bug,因为xcode6一起下载的sdk包里面一些头文件是xocde5里面sdk找不到的,xcode6没有向前兼容xcode5,所以如果你在xcode6下创建的项目,拿到xcode5下面有可能会报错。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值