如何在我的code检查是否启用BOOST? [英] How to check in my code if BOOST is enabled?

查看:104
本文介绍了如何在我的code检查是否启用BOOST?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的code的某些部分启用,只有安装了推动作用。

I want some parts of my code to be enabled, only if boost is installed.

我发现接听和<一个href=\"http://stackoverflow.com/questions/3708706/how-to-determine-the-boost-version-on-a-system\">this一。但是,它们都是为了确定升压的版本。

I found this answer and this one. However, they are meant for determining the version of boost.

所以将这样的事情是完全安全的?

So would something like this be totally safe?

#if BOOST_VERSION
  // boost code
#endif

如果不是这样,我应该怎么办呢?

If not, how should I do it?

推荐答案

您将需要自己的宏做条件编译(或与您的构建系统不知何故控制它)。例如:

You will need to make your own macro to do conditional compilation (or control it somehow with your build system). For example:

#ifdef MYPROJ_HAS_BOOST
#  include <boost/filesystem.hpp>
#endif

然后用 -DMYPROJ_HAS_BOOST 编译(或没有)。

您不能依靠 BOOST_VERSION 或从任何其他升压,因为你不知道你是否有推动作用。你可以做一个假&LT;升压/ version.hpp&gt;在那里你不用升压系统头文件,但这是有点怪异,没有比让自己更好具体项目的宏。

You can't rely on BOOST_VERSION or anything else from Boost, because you don't know if you have Boost. You could make a fake <boost/version.hpp> header file on systems where you don't have Boost, but that's sort of weird and no better than making your own project-specific macro.

有些编译器让你的#include&LT;升压/ version.hpp 且仅当没有找到警告;这可能工作,但会给出一个危险的前瞻性的系统警告不加速,甚至可能彻底失败。

Some compilers will let you #include <boost/version.hpp and only warn if it is not found; this may work but will give a dangerous-looking warning on systems without Boost, and may even fail outright.

这篇关于如何在我的code检查是否启用BOOST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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