Issue
My environment:
macOS 10.14
Clion 2018.1.2
gcc-8.2
I want to use Clion to try the rocksdb. I add a new CMakeLists.txt
file at examples directory.
CMakeLists.txt:
add_subdirectory(examples)
examples/CMakeLists.txt:
add_executable(s_test simple_example.cc)
target_link_libraries(s_test ${LIBS})
But when I build the s_test executable, I get the error as follows.
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
And I already installed the gflags previously.
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
How to solve it? Thank you!
Solution
You will need to pull down the gflags package from git hub. I also use CLION.
So, this is the procedure I followed to pull down rocksdb and gflags:
~> cd CLionProjects
~/CLionProjects> git clone [email protected]:facebook/rocksdb.git
~/CLionProjects> cd rocksdb
~/CLionProjects/rocksdb> git clone [email protected]:gflags/gflags.git
I then created gflagss.cmake at
~/CLionProjects/rocksdb/cmake/modules
with the following content:
# - 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)
I then opened the gflags folder in CLion and built glfags.
I then opened a separate CLion window/folder for rocksdb and built that.
Answered By - Gardener Answer Checked By - Gilberto Lyons (WPSolving Admin)