lerouxrgd/ngt-rs

Can cargo run, can't cargo build

paulbricman opened this issue · 4 comments

Hi @lerouxrgd,

When using cargo run and cargo run --release, I can use the ngt-rs crate without any issues. Search works and it's really fast. However, when I use cargo build --release and run the binary, I get the following error:

error while loading shared libraries: libngt.so.1: cannot open shared object file: No such file or directory

I'm not sure if this is an issue with ngt-rs, an issue with the underlying NGT, or an issue with my setup. Do you have any thoughts on this?

Ubuntu 18.04, ngt = "0.4.0"

The only instances of libngt.so.1 on my machine are build artifacts:

project_root/target/release/build/ngt-sys-7e531d7ff98f0bd6/out/lib/libngt.so.1
project_root/target/release/build/ngt-sys-7e531d7ff98f0bd6/out/build/lib/NGT/libngt.so.1

So I think this is an issue of ngt-rs somehow not using the right libs when building?

Yes this is expected, the binary built with cargo build does not contain the shared library libngt.so.1.
However libngt.so.1 has been built along with your regular binary, you can find it with something like:

find target/release -regex .*out/lib/libngt.*

For the final binary to work properly this libngt.so.1 shared library has to be in LD_LIBRARY_PATH. So something like this should work:

LD_LIBRARY_PATH=/path/to/libngt.so.1 your_binary

Usually shared libraries should be installed in /usr/lib, but it depends on your machine setup.
Another way to install it on your machine could be to use cargo install --path . as I assume it would copy libngt.so.1 to the appropriate location on your system (I haven't tried though).

So in your case you can try:

LD_LIBRARY_PATH="project_root/target/release/build/ngt-sys-7e531d7ff98f0bd6/out/lib/:${LD_LIBRARY_PATH}" project_root

Assuming you are running from project_root and your binary is called project_root

It does work this way, thanks for the prompt reply!