在编译时检查框架是否存在? [英] Check for framework's existence at compile time?

查看:126
本文介绍了在编译时检查框架是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个可以选择使用闭源框架的开源项目。如果闭源框架包含在项目中,则会有其他功能。但是如果框架没有包含在项目中,项目仍然应该正确编译。

I'm working on an open-source project that can optionally use a closed-source framework. If the closed-source framework is included in the project, there will be additional functionality. But if the framework isn't included in the project, the project should still compile properly.

如何在编译时检查如果该框架包含在项目中?

How do I check at compile-time if the framework is included in the project?

基本上,我想做这样的事情:

Basically, I want to do something like this:

#ifdef _MY_FRAMEWORK_EXISTS
#import <MyFramework/MyFramework.h>
#endif

我见过2年前的旧问题喜欢这个,但没有答案浮出水面,所以我现在可能会遗漏一些新东西。

I've seen older questions from 2 years ago like this one, but no answer has surfaced so I might be missing something new now.

我不想在运行时通过 NSClassFromString()进行检查,因为这会在编译时失败当我尝试导入 MyFramework 并且它不存在时。

I DON'T want to check at run-time via NSClassFromString(), because this will fail at compile time when I try to import MyFramework and it doesn't exist.

推荐答案

您可以使用__has_include语言扩展名检查是否存在头文件。
http://clang.llvm.org/docs/LanguageExtensions.html#包含文件检查宏

You can check for the presence of a header file using the __has_include language extension. http://clang.llvm.org/docs/LanguageExtensions.html#include-file-checking-macros

但是,这只会告诉您是否安装了头文件。它无法告诉您Link Binary With Libraries是否与其框架相关联。

However, that only tells you if the header file is installed. It can't tell you if "Link Binary With Libraries" has linked to its framework.

这篇关于在编译时检查框架是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆