facebook/rocksdb — pull request #132 by kjk (2014-04-29 21:50:45+00:00)
Title: Improve building of shared library so that it e.g. works with Go bindings

I've run into this issue while trying to use rocksdb Go bindings (https://github.com/ananclub/rocksgo). My tests were done on Ubuntu 12.04

As a background, there is a difference between `g++ -lsnappy rocksdb.cc -o librocksdb.so` and `g++ rocksdb.cc -lsnappy -o librocksdb.so`.

The first version is currently used in the makefile and doesn't seem to record a reference to libsnappy.so in librocksdb.so, while the second version does (as verified by running `ldd librocksdb.so`).

As a result, if you currently do in rocksdb (assuming go 1.2.1 is installed):
```
make clean
make shared_lib
sudo cp --preserve=links ./librocksdb.* /usr/local/lib/
sudo cp -r ./include/rocksdb/ /usr/local/include/

go get -u github.com/ananclub/rocksgo
```

The last step will error out with:
```
github.com/ananclub/rocksgo
/usr/local/lib/librocksdb.so: undefined reference to `clock_gettime'
/usr/local/lib/librocksdb.so: undefined reference to `inflateEnd'
/usr/local/lib/librocksdb.so: undefined reference to `BZ2_bzCompressInit'
/usr/local/lib/librocksdb.so: undefined reference to `deflate'
/usr/local/lib/librocksdb.so: undefined reference to `snappy::RawUncompress(char const*, unsigned long, char*)'
```

What it does say is that Go bindings are trying to link to librocksdb.so but it fails to link because librocksdb.so references functions from e.g. snappy, but doesn't know how to find libsnappy.so.

Admittedly, maybe there is a reason for doing it the way it's done currently. What I can tell for sure:
* this change fixes Go bindings
* leveldb 1.15 makefile puts `-lsnappy` after sources and therefore doesn't have this problem
* running `ldd librocksdb.so` before this change doesn't show e.g. libsnappy.so and does show after this change