1. Go to the official website http://code.google.com/p/snappy/Download snappy-1.1.1.tar.gz installation package.
2. Pressure to the specified directoryCD ~/snappy
TAR-ZXVF snappy-1.1.1.tar.gz
CD snappy-1.1.1
./configure
Make
At this point, if you continue to make install, the associated library will be installed under/usr/local/lib/, to be customized. Reading Makefile will find everything in
Exec_prefix = ${prefix}
Libdir = ${exec_prefix}/lib
prefix =/usr/local
Next, you know, modify the prefix for you to customize the directory.
Here I set to
prefix = ~/bin
3. Use of SnappyIt's easy to talk about how to use
As I set it above, the header file is under ~/include,. A and. So are all under ~/bin
C Style using snappy-c.h
C + + Use Snappy.h
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <iostream>
#include <strings.h>
#include <string.h>
#include <stdlib.h>
#include <sys/ time.h>
#include "snappy.h"
using namespace std;
String generatordata (int len)
{
string ss;
for (int i=0;i<len;++i)
{
ss = "2";
}
ss+= "finsih!!";
return SS;
}
int main ()
{
string s = generatordata (1024);
string compress_s;
int compress_len = snappy::compress (S.c_str (), S.length (), &compress_s);
printf ("inlen:%d,outlen:%d,ret:%d,compress_s:%s\n", S.length (), Compress_s.length (), compress_len,compress_s.c_ STR ());
string srcovery;
BOOL bucom = snappy::uncompress (Compress_s.c_str (), Compress_len, &srcovery);
printf ("srcovery.len:%d,srcovery:%s\n", Srcovery.length (), Srcovery.c_str ());
return 0;
}
Compile:
g++-i$local_inc-o Main Main.cpp-l$local_lib-lsnappy
Local_inc and Local_lib are the directories you install.
Get the executable test 2 file. Whether it's done. No,compress and other APIs rely on libsnappy.so.1 this dynamic library, direct execution will not find the dynamic library.
2 options:
1. Set environment variable in ~/.profile export ld_library_path= $LD _library_path:~/lib
2. Designation of ~/lib in/etc/ld.so.conf
So far, done, can be tested.