[zeromq-dev] zmq_version
Steven McCoy
steven.mccoy at miru.hk
Wed Jan 27 10:40:34 CET 2010
2010/1/27 Martin Sustrik <sustrik at 250bpm.com>
> Peter,
>
> > BTW, don't forget to add a function which returns the version of the
> > ZMQ library. That gives the bindings the chance to check whether they
> > are using the right version. At least for the Common Lisp bindings
> > this is important, because no code is compiled against the header
> > files. If the ZMQ API changes, this can result in error messages which
> > are hard to understand.
>
> Yes, this have been on TODO list for quite a long time already.
>
> Any suggestions about the format? Something like this?
>
> const char *version = zmq_version ();
> // version == "2.0-beta3"
>
>
For the C++ Google Protocol buffers has a pretty neat method of version
checking, just one macro GOOGLE_PROTOBUF_VERIFY_VERSION and it does all the
work for you. A string or set of numbers is not so useful without a defined
means of checking for compatibility.
GLib and presumably a lot of the Gtk projects use a version triplet with
basic macro checker.
if (!GLIB_CHECK_VERSION (1, 2, 0))
g_error ("GLib version 1.2.0 or above is needed");
http://library.gnome.org/devel/glib/stable/glib-Version-Information.html
Here are the relevant pieces inside protobufs,
// The current version, represented as a single integer to make comparison
// easier: major * 10^6 + minor * 10^3 + micro
#define GOOGLE_PROTOBUF_VERSION 2001000
// The minimum library version which works with the current version of the
// headers.
#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 2001000
// The minimum header version which works with the current version of
// the library. This constant should only be used by protoc's C++ code
// generator.
static const int kMinHeaderVersionForLibrary = 2001000;
// Verifies that the headers and libraries are compatible. Use the macro
// below to call this.
void LIBPROTOBUF_EXPORT VerifyVersion(int headerVersion, int
minLibraryVersion,
const char* filename);
// Converts a numeric version number to a string.
string LIBPROTOBUF_EXPORT VersionString(int version);
#define GOOGLE_PROTOBUF_VERIFY_VERSION \
::google::protobuf::internal::VerifyVersion( \
GOOGLE_PROTOBUF_VERSION, GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION, \
__FILE__)
void VerifyVersion(int headerVersion,
int minLibraryVersion,
const char* filename) {
if (GOOGLE_PROTOBUF_VERSION < minLibraryVersion) {
// Library is too old for headers.
GOOGLE_LOG(FATAL)
<< "This program requires version " <<
VersionString(minLibraryVersion)
<< " of the Protocol Buffer runtime library, but the installed version
"
"is " << VersionString(GOOGLE_PROTOBUF_VERSION) << ". Please
update "
"your library. If you compiled the program yourself, make sure
that "
"your headers are from the same version of Protocol Buffers as your
"
"link-time library. (Version verification failed in \""
<< filename << "\".)";
}
if (headerVersion < kMinHeaderVersionForLibrary) {
// Headers are too old for library.
GOOGLE_LOG(FATAL)
<< "This program was compiled against version "
<< VersionString(headerVersion) << " of the Protocol Buffer runtime "
"library, which is not compatible with the installed version ("
<< VersionString(GOOGLE_PROTOBUF_VERSION) << "). Contact the program
"
"author for an update. If you compiled the program yourself, make
"
"sure that your headers are from the same version of Protocol
Buffers "
"as your link-time library. (Version verification failed in \""
<< filename << "\".)";
}
}
string VersionString(int version) {
int major = version / 1000000;
int minor = (version / 1000) % 1000;
int micro = version % 1000;
return strings::Substitute("$0.$1.$2", major, minor, micro);
}
--
Steve-o
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20100127/e1fee6cd/attachment.htm>
More information about the zeromq-dev
mailing list