gsamaras
gsamaras

Reputation: 73394

How to check in my code if BOOST is enabled?

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

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?

Upvotes: 1

Views: 461

Answers (1)

John Zwinck
John Zwinck

Reputation: 249444

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

Then compile with -DMYPROJ_HAS_BOOST (or not).

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.

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.

Upvotes: 4

Related Questions