If you want to know more information about RocksDB, go to there: http://rocksdb.org/
RockDB requires some new libraries that do not support ubuntu 12.04. I’ll help you install step by step to do it.
1) Install gcc and g++ version 4.8
– Check your gcc and g++ version:
1 | gcc --version |
and
1 | g++ --version |
If gcc and g++ haven’t installed in your OS or their version < 4.7, you must install them by comand lines below:
– Add PPA to your repositories:
1 2 | sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt-get update |
– Unistall the alternative:
1 2 | sudo update-alternatives --remove-all gcc sudo update-alternatives --remove-all g++ |
– Install:
1 2 | sudo apt-get install gcc-4.8 sudo apt-get install g++-4.8 |
– Alternative packages install:
1 2 3 4 | sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 20 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 20 sudo update-alternatives --config gcc sudo update-alternatives --config g++ |
at the end:
1 2 3 | sudo apt-get update sudo apt-get upgrade -y sudo apt-get dist-upgrade |
2) Install the libararies:
* [zlib](http://www.zlib.net/) – a library for data compression.
1 | sudo apt-get install zlib1g-dev |
* [bzip2](http://www.bzip.org/) – a library for data compression.
1 | sudo apt-get install libbz2-dev |
* [snappy](https://code.google.com/p/snappy/) – a library for fast
data compression.
1 | sudo apt-get install libsnappy-dev |
* [gflags](https://code.google.com/p/gflags/) – a library that handles
– Go to page: https://github.com/schuhschuh/gflags
– Download gflags compressed file.
– Extract file and cd to gflags-master folder
1 | ./configure |
1 | make |
1 | sudo make install |
3) Install rocksdb:
– Download zip file from: https://github.com/facebook/rocksdb
– Extract file and cd to rocksdb-master
1 | make |
1 | sudo make install |
4) Create test project
After installing all libraries required by RocksDB. We will create a test project. In this case, I use Netbeans IDE:
1. Create an C++ Application
2. Create library
– Go to your project folder, in this project folder, we create a folder and named it as “lib”.
– Go to folder rocksdb-master that we had built and copy folder rocksdb-master/include/rocksdb to <your project folder>/lib.
– Copy library rocks-master/librocksdb.a to <your project folder>/lib and /usr/lib.
– Now make sure that you had installed bz2 and snappy. Go to /usr/lib and copy libraries: libbz2.a, libsnappy.a to <your project folder>/lib.
3. Configure your project:
Right click on Netbeans project and chose Properties.
– In Build > C++Complier > C++ Standard chose C++11.
– In Build > C++Complier> Include Directories and Headers, link to <your project folder>/lib.
– In Build > Linker > Addition Library Directories, link to <your project folder>/lib.
– In Build > Linker > Libraries, chose Add Libraries and chose all .a files in <your project folder>/lib we had copied.
– In Build > Linker > Additional Options: add “-lz -lpthread -lrt”.
Now let’s try to copy source code below to main file in your project and build:
1 2 3 4 5 6 7 8 9 10 11 | #include <assert.h> #include "rocksdb/db.h" int main( int argc, char ** argv) { rocksdb::DB *db; rocksdb::Options options; options.create_if_missing = true ; rocksdb::Status status = rocksdb::DB::Open(options, "/tmp/testdb/" , &db); assert (status.ok()); return 0; } |
Enjoy!