4

我按照指南做了:

brew install rocksdb

我被困在这里。我该怎么做才能使用rocksdb

我复制了这个示例文件的内容并尝试在 Mac OS 上使用gcc-5(brew) 和(clang) 编译它,但它们都返回错误。gcc我在 Mac OS 10.11.5 上使用 Xcode 7.3.1。

错误是:

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

更新:

将rocksdb库添加到Xcode中的Header和Library Search Path之后,如下所示:

xcode 截图

我在rocksdb网站上试过

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

并遇到了另一个问题:

DBOptions 问题

4

1 回答 1

2

您必须告诉链接器rocksdb库在哪里以及它被称为什么,以便它可以找到符号。

假设homebrew安装rocksdb/usr/local/Cellar/rocksdb/4.5.1,你可能会想要类似的东西:

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

或者,也许是版本特定的东西,因为它无论如何都是符号链接的:

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

如果您想使用 Xcode GUI(而不是命令行),您需要按照本文中的绿色、黄色、蓝色、红色的内容进行操作,要填写上述值rocksdb

于 2016-06-04T10:51:01.070 回答