在 MacOS 的 Clion 中,rocksdb 构建失败

蒂芬妮

我的环境:

macOS 10.14
Clion 2018.1.2
gcc-8.2

我想用 Clion 来试试 Rocksdb。CMakeLists.txt在示例目录中添加了一个新文件。

CMakeLists.txt

add_subdirectory(examples)

示例/CMakeLists.txt

add_executable(s_test simple_example.cc)
target_link_libraries(s_test ${LIBS})

但是当我构建 s_test 可执行文件时,我收到如下错误。

Linking CXX shared library librocksdb.dylib
Undefined symbols for architecture x86_64:
"google::FlagRegisterer::FlagRegisterer<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(char const*, char const*, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)", referenced from:
  __static_initialization_and_destruction_0(int, int) in db_bench_tool.cc.o
  __static_initialization_and_destruction_0(int, int) in trace_analyzer_tool.cc.o
"google::SetUsageMessage(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
  rocksdb::db_bench_tool(int, char**) in db_bench_tool.cc.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[3]: *** [librocksdb.5.17.0.dylib] Error 1
make[2]: *** [CMakeFiles/rocksdb-shared.dir/all] Error 2
make[1]: *** [examples/CMakeFiles/s_test.dir/rule] Error 2

而且我之前已经安装了 gflags。

ls /usr/local/lib | grep gflags

libgflags.2.2.1.dylib
libgflags.2.2.dylib
libgflags.dylib
libgflags_nothreads.2.2.1.dylib
libgflags_nothreads.2.2.dylib
libgflags_nothreads.dylib

如何解决?谢谢!

园丁

您需要从 git hub 拉下 gflags 包。我也用 CLION。

所以,这是我拉下rocksdb和gflags的过程:

~> cd CLionProjects
~/CLionProjects> git clone [email protected]:facebook/rocksdb.git
~/CLionProjects> cd rocksdb
~/CLionProjects/rocksdb> git clone [email protected]:gflags/gflags.git

然后我创建了 gflagss.cmake 在

~/CLionProjects/rocksdb/cmake/modules

具有以下内容:

# - Find GFLAGS

set(GFLAGS_ROOT_DIR ./gflags/cmake-build-debug)
find_path(GFLAGS_INCLUDE_DIR
  NAMES bzlib.h
  HINTS ${GFLAGS_ROOT_DIR}/include)

find_library(GFLAGS_LIBRARIES
  NAMES gflags
  HINTS ${GFLAGS_ROOT_DIR}/lib)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(bzip2 DEFAULT_MSG BZIP2_LIBRARIES BZIP2_INCLUDE_DIR)

mark_as_advanced(
  GFLAGS_LIBRARIES
  GFLAGS_INCLUDE_DIR)

然后我在 CLion 中打开了 gflags 文件夹并构建了 glfags。

然后我为rocksdb打开了一个单独的CLion窗口/文件夹并构建了它。

如果这有帮助,请告诉我。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章