1. 安装依赖
1
sudo apt-get install gcc g++ libsnappy-dev zlib1g-dev libbz2-dev liblz4-dev libzstd-dev libgflags-dev
  1. 下载安装包并解压(安装包链接放在最后)
1
2
tar -xzvf rocksdb-6.16.6.tar.gz
cd rocksdb-6.16.4/
  1. 编译安装
1
2
3
4
// 编译静态库
make static_lib
// 编译动态库
make shared_lib

如果出现下面的错误:

1
2
3
4
5
// 错误示例
$DEBUG_LEVEL is 0
GEN util/build_version.cc
CCLD librocksdb.so.6.13.0
/usr/bin/ld: ./memory/concurrent_arena.o: relocation R_X86_64_TPOFF32 against symbol _ZN7rocksdb15ConcurrentArena9tls_cpuidE' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: ./monitoring/iostats_context.o: relocation R_X86_64_TPOFF32 against symbol _ZN7rocksdb15iostats_contextE' can not be used when making a shared object; recompile with -fPIC

解决方法:

1
2
3
make clean
make shared_lib
make static_lib

编译完成会得到下面几个文件(第一个为静态编译得到的,后四个为动态编译得到的)

1
2
3
4
5
librocksdb.a
librocksdb.so
librocksdb.so.6
librocksdb.so.6.16
librocksdb.so.6.16.4
  1. 环境配置(我这里软连接创建失败了,但是没有影响安装)
1
2
3
4
5
6
// 将动态库文件复制到系统库目录下
sudo cp librocksdb.so.6.16.4 /usr/local/lib
// 链接其他动态库
sudo ln -s librocksdb.so.6.16.4 /usr/local/lib/librocksdb.so.6.16
sudo ln -s librocksdb.so.6.16.4 /usr/local/lib/librocksdb.so.6
sudo ln -s librocksdb.so.6.16.4 /usr/local/lib/librocksdb.so

vi /etc/profile

1
2
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH

最后source /etc/profile
致此安装完毕

安装包链接:
链接:https://pan.baidu.com/s/1oFANkJPUIQUzwJLF3NF3mw
提取码:ofwb

文章摘自https://www.jianshu.com/p/575b2e27b028