0

I am trying to compile a program that uses rocksdb.

According to the example in the official webpage, the only header i should add to my code is db.h.

Now, the file i am compiling is in folder A. db.h however is in A/rocksdb-master/include/rocksdb/.

So, i add this line to my file:

#include "rocksdb-master/include/rocksdb"

It finds the file, but the problem is that inside db.h, i have this line:

#include "rocksdb/metadata.h"

And when i compile i get this error:

fatal error: rocksdb/metadata.h: No such file or directory #include "rocksdb/metadata.h"

I mean, it's obvious. db.h is in the same folder as metadata.h, so it's fine that the compiler cant find any rocksdb folder. But i doubt that people who wrote this library don't know that.

Is there any other way to add the path's to compile it? Why is it that the path from db.h are not relative to where it is located?

user3013172
  • 1,637
  • 3
  • 15
  • 26
  • 1
    You should probably add "rocksdb-master/include" to the include path for your compiler. How you do that depends on the compiler. – Bo Persson Aug 31 '15 at 22:17
  • The reason for not having just `#include "metadata.h"` is of course that a lot of libraries have such a file. – Bo Persson Aug 31 '15 at 22:18

1 Answers1

3

You should normally use just the following header in your project:

#include "rocksdb/db.h"

When compiling your own project, you should then add the RocksDB include path to the list of include directories. For example, if the RocksDB source code is in directory ../rocksdb-master, the include path will be ../rocksdb-master/include.

How to add the include path to the compiler flags is indeed compiler-specific. With g++ or clang, it's done by passing -I../rocksdb-master/include to the compiler when compiling your own program. Note that you many need to link against the RocksDB library as well.

And finally, you may need to include some more RocksDB headers if you use some of its advanced concepts, e.g. transactions.

stj
  • 9,037
  • 19
  • 33