I am writing a C++ library that uses boost.
In this library I want to include information about the boost version that was used to compile the binary version of my library.
I can use the macro BOOST_VERSION
and this is fine.
I also wanted to determine which is the runtime version of boost so I could compare with the boost version that was used to compile my library. Obviously I cannot use the macro because it will give me the hard coded version at compile time, not at runtime.
What I needed is a function in boost (like boost::get_version()
). Is there a way to do this in boost?
You can use the macro to create some code as follows:
This works on boost 1.51.x and upwards. Not sure if this is what you are looking for though, I will keep going and see if there is a way to get it from the currently loaded dll in a more elegant way.
Addendum:
To find run-time versions:
After looking at the Boost system, it seems that the simplest way you could do what you are looking for would be to have platform dependant code which is utilised at compiletime to make the different versions of executable.
For Windows:
You will need to query the DLL for its version using GetFileVersionInfoEx API or GetFileVersionInfo API, you also need to take into account if the OS is 32 bit or 64 bit, so here is some code which may be of use:
Then we can utilise a straight-forward bit of code to get the version of the DLL:
For Linux:
Horribly cant remember the code for that at present, however here is a partial solution from memory (I don't have a Linux machine to hand at the moment, will check this in more detail later, but should work with only minor modifications at most).
Combining the two:
To make the same thing happen in multiple OSes you would probably have to use something like:
Now dependant upon which OS this is compiled for, the right function will be pointed at by the
detectBoostDLLVersion()
function :)There is no such feature in boost and I think you can only scan binary file for this thing (
ldd
in linux for example).