Compile LevelDB as a shared library

AxLabs
Aug 19, 2021

--

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. πŸ˜ƒ

πŸ’ͺ πŸŽ‰

--

--

AxLabs
AxLabs

Written by AxLabs

Breaking down the barrier to Web3, one dApp at a time.

No responses yet