RocksDB is a high performance embedded key value storage engine which is written in C++. Though its name tells that it is a database, it is actually a C++ library providing a bunch of API instead of a Client-Server architected database.
I am not a C++ programmer and when trying to play with RocksDB following the Getting Started guide from the RocksDB website, I found it is not easy to run the example in CentOS 7 with either dynamic or static linkage. To be more specific with dynamic linkage, the search paths of dynamic libraries vary from Linux distributions but the installation script of RocksDB does not take care of that.
This post is intended for those who want to play with RocksDB but failed to run the example. What will be mentioned including
- How to install RocksDB as dynamic library from source in CentOS 7
- How to install RocksDB as static library in CentOS 7
- How to run the example program
Here is the demo program
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Before you continue, please install the dependencies.
Install the shared lib
First, run the command line to build dynamic library
Makefile provides a target called
install-shared to install RocksDB shared lib.
The target actually includes two jobs:
- Copy all the header files under
- Copy the
.sofile and symbolic links to
Run the example
- Compile the program with following command
- Run the program with
./demoand an error occurs
The problem with the
install-shared target is that
/usr/local/lib is in
g++’s dynamic library search paths but not in
ldconfig’s in CentOS 7 by default. So the program can be built during compiling time but will cause dynamic library load error during run time. This can be verified by following commands:
- Show search paths of g++
- Show search paths of ldconfig
There are 2 ways to resolve the issue. And EITHER one is ok.
.sofile and symbolic links into both the search paths of
ldconfig’s search paths.
As mentioned before,
/usr/local/lib is in g++’s search path, thus there is no such dynamic load issue with static RocksDB. First build and install static RocksDB.
Then compile the demo program with
Don’t miss the
The problem is caused by shared library search paths which could vary from different Linux distributions. A good solution to avoid the issue is packaging the files into a rpm package, and deb package in Debian platform of course.
It is worth noting that
/usr/lib64, instead of
/usr/lib, is the common place to hold the lib files in x86_64 RedHat family OSes such as CentOS, Fedora. Though
/usr/lib works but
/usr/lib64 is a better place for the lib files in RedHat family. There is a patch to take care of that when creating a RPM.