basho / eleveldb

Erlang LevelDB API
263 stars 176 forks source link

Compilation error when snappy is already installed #270

Closed codeadict closed 1 year ago

codeadict commented 1 year ago

When libsnappy has been already installed via the OS package manager. Compiling eleveldb fails with the following error:

This happens on Ubuntu 22.04 and OTP 25.

===> Linking priv/eleveldb.so
===> sh(cc c_src/eleveldb.o c_src/refobjects.o c_src/workitems.o $LDFLAGS $LDLIBS -shared  -L"/home/il/Erlangs/25.2/lib/erl_interface-5.3/lib" -lei c_src/leveldb/libleveldb.a c_src/system/lib/libsnappy.a -lstdc++ -o priv/eleveldb.so)
failed with return code 1 and the following output:
/usr/bin/ld: c_src/system/lib/libsnappy.a(snappy.cc.o): relocation R_X86_64_PC32 against symbol `_ZTVN6snappy4SinkE' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status

make: *** [Makefile:22: rel] Error 1
martinsumner commented 1 year ago

I'm out of my depth here when it comes to make scripts.

With a bit of help from google, perhaps adding --with-pic to the ./configure in https://github.com/basho/eleveldb/blob/develop/c_src/Makefile#L36 might work?

Perhaps @hmmr may be able to help

hmmr commented 1 year ago

When I was preparing #266, I took a conservative approach and left code that downloads snappy and builds it. Now, however, I tend to think it's best to just rely on libsnappy preinstalled.

Regarding this particular error, can there be something in your LDFLAGS that shouldn't be there?

hmmr commented 1 year ago

Opened #271, to simplify things.

codeadict commented 1 year ago

Indeed, if we don't require a specific Snappy version, it might be better to rely on the OS one. @hmmr Thanks so much, I'll try your changes on my m1 mac

codeadict commented 1 year ago

@hmmr I've opened https://github.com/basho/eleveldb/pull/272 on top of your PR and added OSX to CI to ensure it never breaks. I'm still unsure if this works on all OSes until CI runs. I've tested it on my M1 mac and it works fine. @ioolkos If you can please give it a shot on your OS that would be great too.

ioolkos commented 1 year ago

@codeadict https://github.com/basho/eleveldb/pull/272 builds without issues for me on Ubuntu 20.04 and 22.04 (both with OTP 25)

codeadict commented 1 year ago

@ioolkos It compiles but does not load the nif correctly if you try using eleveldb from the shell. Fails with {error,{load_failed,"Failed to load NIF library: '/home/runner/work/eleveldb/eleveldb/_build/test/lib/eleveldb/priv/eleveldb.so: undefined symbol: _ZN6snappy21GetUncompressedLengthEPKcmPm'"}} which probably indicates it expects snappy 1.1.9 that has a different signature and Ubuntu and Debian systems most have 1.1.8. I'm out of ideas here. So probably downloading and compiling snappy was not a bad idea, its what the erlang_rocksdb library does too but we have to find a way for the package manager installed library to not interfere with compiled one

ioolkos commented 1 year ago

@codeadict hm, you're right, just confirmed this. sorry for not testing properly. I'll try to see whether I can find anything to do about this on Ubuntu.

codeadict commented 1 year ago

Here is a job running these tests https://github.com/codeadict/eleveldb/actions/runs/4227609076.