I’m working on a C++ maths library in which I want to be able to configure at compile time using defines.
One of the configurations is defining the precision. In code it looks like this:
#ifdef MYMATH_USE_DOUBLE
typedef double Real;
#else
typedef float Real;
#endif
That works fine.
If someone wants to then use the library after it has been configured with MYMATH_USE_DOUBLE they’ll have to also pass that define to the compiler.
Is there a better way of doing this?
I don’t want the user to have to remember what defines were used to compile the maths librarys and then repeat them all for their app.
Usually, the best practice is to run “configure” script, that creates one file with all defines. And this file is included in all headers. For example, if you compile OpenSSL from sources, “configure” creates e_os.h (as far as a remember the name), that is included practically in every header.