Building snappy compression library on windows with Visual Studio 2012

Snappy is a little fast software compression library by google. It eschews high compression rates for speed, it is very easy to use. Building it on windows for use with visual studio etc. is relatively straight-forward due to this github project by kmanley which provides it with a visual studio solution.

https://github.com/kmanley/snappy-msvc

To build the snappy static libraries, follow the instructions on the github page (README.rst).

If you get a build error like this:

Then copy the following code and place it at the top of the snappy.h header file (say, after #define UTIL_SNAPPY_SNAPPY_H__):

Once it has built, snappy.lib can be found in the Debug or Release folders, note that the debug build of the snappy lib is very slow so don’t do any tome testing with it! The release build screams along!

To use snappy in your C/C++ project you will need to #include “snappy.h” (which in-turn uses “snappy-stubs-public.h”) and also add snappy.lib to your project. Here is a little silly example:

If you get an error like this when you try to compile your client code:

Then it means you are trying to use the debug version of snappy.lib in a release build or vice versa, use the correct version and the error should go away….

Many thanks to kmanley!