pmelsted / bifrost

Bifrost: Highly parallel construction and indexing of colored and compacted de Bruijn graphs
BSD 2-Clause "Simplified" License
201 stars 25 forks source link

Locally installed executable cannot find shared library #66

Closed rlorigro closed 1 year ago

rlorigro commented 1 year ago

Hi,

I installed Bifrost according to your instructions in order to create the bin and lib directories inside my path of choice (the build directory). However, when running the executable bin/Bifrost it cannot find the necessary libbifrost.so, so it is not usable. I used the LD_DEBUG method on Ubuntu 20.04 to show that it only searches root and usr directories:

ryan@computron:~/software/bifrost/build/bin$ LD_DEBUG=all ./Bifrost 
     19678: file=libbifrost.so [0];  needed by ./Bifrost [0]
     19678: find library=libbifrost.so [0]; searching
     19678:  search cache=/etc/ld.so.cache
     19678:  search path=/lib/x86_64-linux-gnu/tls/haswell/x86_64:/lib/x86_64-linux-gnu/tls/haswell:/lib/x86_64-linux-gnu/tls/x86_64:/lib/x86_64-linux-gnu/tls:/lib/x86_64-linux-gnu/haswell/x86_64:/lib/x86_64-linux-gnu/haswell:/lib/x86_64-linux-gnu/x86_64:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu/tls/haswell/x86_64:/usr/lib/x86_64-linux-gnu/tls/haswell:/usr/lib/x86_64-linux-gnu/tls/x86_64:/usr/lib/x86_64-linux-gnu/tls:/usr/lib/x86_64-linux-gnu/haswell/x86_64:/usr/lib/x86_64-linux-gnu/haswell:/usr/lib/x86_64-linux-gnu/x86_64:/usr/lib/x86_64-linux-gnu:/lib/tls/haswell/x86_64:/lib/tls/haswell:/lib/tls/x86_64:/lib/tls:/lib/haswell/x86_64:/lib/haswell:/lib/x86_64:/lib:/usr/lib/tls/haswell/x86_64:/usr/lib/tls/haswell:/usr/lib/tls/x86_64:/usr/lib/tls:/usr/lib/haswell/x86_64:/usr/lib/haswell:/usr/lib/x86_64:/usr/lib        (system search path)
     19678:   trying file=/lib/x86_64-linux-gnu/tls/haswell/x86_64/libbifrost.so
     19678:   trying file=/lib/x86_64-linux-gnu/tls/haswell/libbifrost.so
     19678:   trying file=/lib/x86_64-linux-gnu/tls/x86_64/libbifrost.so
     19678:   trying file=/lib/x86_64-linux-gnu/tls/libbifrost.so
     19678:   trying file=/lib/x86_64-linux-gnu/haswell/x86_64/libbifrost.so
     19678:   trying file=/lib/x86_64-linux-gnu/haswell/libbifrost.so
     19678:   trying file=/lib/x86_64-linux-gnu/x86_64/libbifrost.so
     19678:   trying file=/lib/x86_64-linux-gnu/libbifrost.so
     19678:   trying file=/usr/lib/x86_64-linux-gnu/tls/haswell/x86_64/libbifrost.so
     19678:   trying file=/usr/lib/x86_64-linux-gnu/tls/haswell/libbifrost.so
     19678:   trying file=/usr/lib/x86_64-linux-gnu/tls/x86_64/libbifrost.so
     19678:   trying file=/usr/lib/x86_64-linux-gnu/tls/libbifrost.so
     19678:   trying file=/usr/lib/x86_64-linux-gnu/haswell/x86_64/libbifrost.so
     19678:   trying file=/usr/lib/x86_64-linux-gnu/haswell/libbifrost.so
     19678:   trying file=/usr/lib/x86_64-linux-gnu/x86_64/libbifrost.so
     19678:   trying file=/usr/lib/x86_64-linux-gnu/libbifrost.so
     19678:   trying file=/lib/tls/haswell/x86_64/libbifrost.so
     19678:   trying file=/lib/tls/haswell/libbifrost.so
     19678:   trying file=/lib/tls/x86_64/libbifrost.so
     19678:   trying file=/lib/tls/libbifrost.so
     19678:   trying file=/lib/haswell/x86_64/libbifrost.so
     19678:   trying file=/lib/haswell/libbifrost.so
     19678:   trying file=/lib/x86_64/libbifrost.so
     19678:   trying file=/lib/libbifrost.so
     19678:   trying file=/usr/lib/tls/haswell/x86_64/libbifrost.so
     19678:   trying file=/usr/lib/tls/haswell/libbifrost.so
     19678:   trying file=/usr/lib/tls/x86_64/libbifrost.so
     19678:   trying file=/usr/lib/tls/libbifrost.so
     19678:   trying file=/usr/lib/haswell/x86_64/libbifrost.so
     19678:   trying file=/usr/lib/haswell/libbifrost.so
     19678:   trying file=/usr/lib/x86_64/libbifrost.so
     19678:   trying file=/usr/lib/libbifrost.so
     19678: 
./Bifrost: error while loading shared libraries: libbifrost.so: cannot open shared object file: No such file or directory

Is it possible to create a static executable so that this can be run/installed locally? Or otherwise somehow pass the install prefix to the executable RPATH in cmake?

Thanks

GuillaumeHolley commented 1 year ago

Hi @rlorigro,

Did you do a sudo make install after doing make? This command installs all the right files in the right paths. By default, the Bifrost binary looks for the Bifrost library in a path which is in your LIBRARY_PATH and LD_LIBRARY_PATH variables. If you did not do a sudo make install, the library was not copied there so you end up with this library not found error. If you could not do a sudo make install because you do not have sudo privileges, you have 2 options:

I hope this help but let me know if this doesn't work.

Guillaume

rlorigro commented 1 year ago

Hi Guillaume,

Thanks for the quick response. I used this command (to install directly into the build directory):

ryan@computron:~/software/bifrost/build/bin$ cmake .. -DCMAKE_INSTALL_PREFIX=./

Setting the environment variables is ok, but I thought it would be convenient to do it in a more unified way. I understand if you have other priorities though.

I think it should be possible to add the correct library path to the executable using CMake, if you are interested in that. Here is one example solution: https://stackoverflow.com/a/43551534

Otherwise, a static executable should also be possible?

Thanks

GuillaumeHolley commented 1 year ago

Your cmake command is just fine but since the library is now installed in a "non-standard" local path, you need to change your environment variables to add this "non-standard" path to it. Indicating to cmake where to install/find the shared library is ok but I think it defeats the purpose of using a shared library. As you suggested, a static binary would be better for your use case. I'll add this to my todo list.

Guillaume

rlorigro commented 1 year ago

Great thanks!

GuillaumeHolley commented 1 year ago

Closing for now but I'll notify you here when the static binary feature is up and running.