在 MacOS 上开始使用rocksdb
Posted
技术标签:
【中文标题】在 MacOS 上开始使用rocksdb【英文标题】:Getting started with rocksdb on MacOS 【发布时间】:2016-06-03 13:54:04 【问题描述】:我跟着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 website
rocksdb::DB* db;
rocksdb::Options options;
又遇到了一个问题:
【问题讨论】:
【参考方案1】:您必须告诉链接器 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(而不是命令行),您需要按照 this post 中的绿色、黄色、蓝色、红色事物的轨迹,但将 rocksdb
的值填写为以上。
【讨论】:
你好@mark-setchell,我稍微更新了我的问题,你能看一下吗? 您似乎仍然缺少链接帖子的“红色”部分 - 您仍然需要在 Xcode 的Other Linker Flags
部分中使用 -lrocksdb
。
太棒了。非常感谢马克,你拯救了我的一天。以上是关于在 MacOS 上开始使用rocksdb的主要内容,如果未能解决你的问题,请参考以下文章
终于要来了吗?苹果在 iOS 和 macOS 上使用同样的应用?
LuaJIT版从零开始在 macOS 上配置 Lua 开发环境