系统为:Ubuntu18.04
Dependencies:
sudo apt-get install libgflags-dev \
libsnappy-dev \
zlib1g-dev \
libbz2-dev \
liblz4-dev \
libzstd-dev
使用
create_db.cpp
#include <assert.h>
#include "rocksdb/db.h"
int main()
{
rocksdb::DB* db;
rocksdb::Options options;
options.create_if_missing = true;
rocksdb::Status status = rocksdb::DB::Open(options, "/home/ubuntu/rocksdb_test/testdb", &db);
assert(status.ok());
return 0;
}
CMakeLists.txt
# Passed
# PROJECT(CREATEDB)
# LINK_LIBRARIES("/home/ubuntu/3rd/rocksdb/librocksdb.a")
# INCLUDE_DIRECTORIES(/home/ubuntu/3rd/rocksdb/include)
# find_library(LZ4_LIB lz4)
# message(STATUS "finding ${LZ4_LIB}")
# ADD_EXECUTABLE(create_db create_db.cpp)
# TARGET_LINK_LIBRARIES(create_db ${LZ4_LIB} -lpthread -lsnappy -lz -lbz2 -lzstd -ldl)
PROJECT(CREATEDB)
LINK_LIBRARIES("/home/ubuntu/3rd/rocksdb/librocksdb.a")
INCLUDE_DIRECTORIES(/home/ubuntu/3rd/rocksdb/include)
ADD_EXECUTABLE(create_db create_db.cpp)
TARGET_LINK_LIBRARIES(create_db z4 pthread snappy z bz2 zstd dl)
运行create_db
创建数据库
(base) ubuntu@VM-8-7-ubuntu:~/rocksdb_test$ tree testdb/
testdb/
├── 000005.log
├── CURRENT
├── IDENTITY
├── LOCK
├── LOG
├── MANIFEST-000004
└── OPTIONS-000007
0 directories, 7 files