Compile LevelDB as a shared library

These days quite a lot of projects use the really nice key-value database called LevelDB.

Sometimes you might need to compile LevelDB for whatever reason β€” of which I would not list here for the sake of my health. πŸ˜…

But we were surprised that LevelDB codebase only compiles a static lib, and not a shared one.

Then, totally by chance, we found out in this issue how to do it β€” saving us tons of time.

Just for documentation purposes, the steps are as follows.

First, change the CMakeLists.txt file:

$ sed -i "s/add_library(leveldb \"\")/add_library(leveldb \"SHARED\")/g" CMakeLists.txt

And then, execute the cmake command with some more options:

$ env BUILD_SHARED_LIBS=on cmake -DCMAKE_BUILD_TYPE=Release .. && cmake --build .

In the end, you will see the output of a .soor a .dylib. πŸ˜ƒ

πŸ’ͺ πŸŽ‰

--

--

Tech thinkers & builders. Open-source freaks. Passionate about blockchain engineering. Using bleeding-edge technologies to build rock-solid products.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
AxLabs

Tech thinkers & builders. Open-source freaks. Passionate about blockchain engineering. Using bleeding-edge technologies to build rock-solid products.