mommomonthewind
mommomonthewind

Reputation: 4640

Getting started with rocksdb on MacOS

I followed the guide and did:

brew install rocksdb

and I stuck here. What should I do to use rocksdb?

I copied the content of this example file and tried to compile it, both with gcc-5 (brew) and gcc (clang) on Mac OS, but both of them return error. I am using Xcode 7.3.1 on Mac OS 10.11.5.

The error is:

Undefined symbols for architecture x86_64:
  "_rocksdb_backup_engine_close", referenced from:
      _main in ccNZ2cWh.o
  "_rocksdb_backup_engine_create_new_backup", referenced from:
      _main in ccNZ2cWh.o
  "_rocksdb_backup_engine_open", referenced from:
      _main in ccNZ2cWh.o
  "_rocksdb_backup_engine_restore_db_from_latest_backup", referenced from:
      _main in ccNZ2cWh.o
  "_rocksdb_close", referenced from:
      _main in ccNZ2cWh.o
  "_rocksdb_get", referenced from:
      _main in ccNZ2cWh.o
  "_rocksdb_open", referenced from:
      _main in ccNZ2cWh.o
  "_rocksdb_options_create", referenced from:
      _main in ccNZ2cWh.o
  "_rocksdb_options_destroy", referenced from:
      _main in ccNZ2cWh.o
  "_rocksdb_options_increase_parallelism", referenced from:
      _main in ccNZ2cWh.o
  "_rocksdb_options_optimize_level_style_compaction", referenced from:
      _main in ccNZ2cWh.o
  "_rocksdb_options_set_create_if_missing", referenced from:
      _main in ccNZ2cWh.o
  "_rocksdb_put", referenced from:
      _main in ccNZ2cWh.o
  "_rocksdb_readoptions_create", referenced from:
      _main in ccNZ2cWh.o
  "_rocksdb_readoptions_destroy", referenced from:
      _main in ccNZ2cWh.o
  "_rocksdb_restore_options_create", referenced from:
      _main in ccNZ2cWh.o
  "_rocksdb_restore_options_destroy", referenced from:
      _main in ccNZ2cWh.o
  "_rocksdb_writeoptions_create", referenced from:
      _main in ccNZ2cWh.o
  "_rocksdb_writeoptions_destroy", referenced from:
      _main in ccNZ2cWh.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

Update:

After adding rocksdb library to Header and Library Search Path in Xcode as follow:

xcode screenshot

I tried as on rocksdb website

rocksdb::DB* db;
rocksdb::Options options;

and met another problem:

DBOptions problem

Upvotes: 4

Views: 6139

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207485

You must tell the linker where the rocksdb library is and what it is called so it can find the symbols.

Assuming homebrew installed rocksdb into /usr/local/Cellar/rocksdb/4.5.1, you will probably want something like:

gcc-5 -std=c++11 program.c -o program -L /usr/local/Cellar/rocksdb/4.5.1/lib -lrocksdb

or, maybe something less version-specific since it is symlinked anyway:

gcc-5 -std=c++11 program.c -o program -L /usr/local/lib -lrocksdb

If you want to use the Xcode GUI (rather than the command-line), you will need to follow the trail of green, yellow, blue, red things in this post but fill in the values for rocksdb as above.

Upvotes: 2

Related Questions