Well, the question was a little off track, but the actual issue is important.
If for some of your methods you really need to depend on a library that most users donβt like, itβs quite reasonable to be prepared to rid them of this unnecessary dependency.
You can do this by manipulating the preprocessor tokens.
/// myClass.h /// In order to use BigDep, you need to: /// - define `MYPROJECT_BIGDEP_USE` before included this header /// - have `<bigdep-install-path>/include` in your include path /// - link with `libbigdep.so` class MyClass { public: void foo() const;
Thus, you must compile the mode, depending on whether the character MYPROJECT_BIGDEP_USE or not.
In gcc, you can define a character on the command line using -D , as in -DMYPROJECT_BIGDEP_USE . In Visual Studio, this is with /D , as in /DMYPROJECT_BIGDEP_USE .
Another option for the user is to wrap the header:
// myProjectMyClass.h
And only ever include "myProjectMyClass.h" and never head directly.
The use of these preprocessor directives is fairly common. For example, when installing the python cx_Oracle module, the installer checked the version of oracle that I used from my environment variables and disabled several methods that were not available to him directly at compile time.
source share