我跟着guide并做了:
brew install rocksdb
我被困在这里。我该怎么做才能使用rocksdb
?
我复制了this example file的内容并试图在Mac OS上使用gcc-5
(brew)和gcc
(clang)编译它,但它们都返回错误。我在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后如下:
rocksdb::DB* db;
rocksdb::Options options;
并遇到了另一个问题:
答案 0 :(得分:2)
您必须告诉链接器rocksdb
库的位置以及它的名称,以便它可以找到符号。
假设自制将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(而不是命令行),则需要跟踪this post中绿色,黄色,蓝色,红色的内容,但要填写{{{ 1}}如上所述。