Closed cjrh closed 2 years ago
I think the error is because you didn't run git submodule update --init
in your local clone ?
As for the statically linking, I think it wasn't possible before, I'll have a look at it again.
The tricky dep for statically linking is openmp if I remember correctly.
didn't run git submodule update --init in your local clone ?
Well spotted, I forgot to update after the new release :)
So when I was playing with static
on the previous release, what I found was that everything "builds" fine (cargo build), but cargo test would fail with a bunch of missing symbols.
I updated the submodule and I'm building again on the new release...
Yup cargo build
succeeds but cargo test
fails:
Compiling ngt v0.4.4 (/home/caleb/tmp/ngt-rs)
error: linking with `cc` failed: exit status: 1
<snip, lots of this:>
/bin/ld: /usr/include/c++/11/ext/new_allocator.h:145: undefined reference to `operator delete(void*)'
/bin/ld: /home/caleb/tmp/ngt-rs/target/debug/deps/libngt_sys-88de9e97cd094267.rlib(Capi.cpp.o): in function `NGT::SearchContainer::~SearchContainer()':
/home/caleb/tmp/ngt-rs/ngt-sys/NGT/lib/NGT/Common.h:2035: undefined reference to `operator delete(void*)'
/bin/ld: /home/caleb/tmp/ngt-rs/target/debug/deps/libngt_sys-88de9e97cd094267.rlib(Capi.cpp.o): in function `__gnu_cxx::new_allocator<char>::deallocate(char*, unsigned long)':
/usr/include/c++/11/ext/new_allocator.h:145: undefined reference to `operator delete(void*)'
/bin/ld: /home/caleb/tmp/ngt-rs/target/debug/deps/libngt_sys-88de9e97cd094267.rlib(Capi.cpp.o): in function `NGT::Exception::~Exception()':
/home/caleb/tmp/ngt-rs/ngt-sys/NGT/lib/NGT/Common.h:69: undefined reference to `std::exception::~exception()'
/bin/ld: /home/caleb/tmp/ngt-rs/target/debug/deps/libngt_sys-88de9e97cd094267.rlib(Capi.cpp.o): in function `NGT::LeafNode::~LeafNode()':
/home/caleb/tmp/ngt-rs/ngt-sys/NGT/lib/NGT/Node.h:420: undefined reference to `operator delete[](void*)'
/bin/ld: /home/caleb/tmp/ngt-rs/target/debug/deps/libngt_sys-88de9e97cd094267.rlib(Capi.cpp.o): in function `NGT::LeafNode::~LeafNode()':
<snip>
I've implemented static
build in 0.4.5
, note that it disables OpenMP when building NGT.
Still, I think using openmp-sys to statically link against host's OpenMP could be interesting too.
I've implemented static build in 0.4.5, note that it disables OpenMP when building NGT.
Thank you!
I pulled 0.4.5 (master branch actually) then did cargo build
followed by cargo test
. The build succeeds but the test fails:
$ cargo test
Compiling crossbeam-utils v0.8.11
Compiling rayon-core v1.9.3
Compiling either v1.8.0
Compiling remove_dir_all v0.5.3
Compiling fastrand v1.8.0
Compiling memoffset v0.6.5
Compiling crossbeam-epoch v0.9.10
Compiling rayon v1.5.3
Compiling num_cpus v1.13.1
Compiling tempfile v3.3.0
Compiling crossbeam-channel v0.5.6
Compiling crossbeam-deque v0.8.2
Compiling ngt v0.4.5 (/home/caleb/tmp/ngt-rs)
Finished test [unoptimized + debuginfo] target(s) in 5.73s
Running unittests src/lib.rs (target/debug/deps/ngt-7334a1c6d8fc0434)
running 7 tests
test optim::tests::test_convert_anng_to_onng ... ignored
test optim::tests::test_optimize_anng ... ignored
test index::tests::test_batch ... ok
test index::tests::test_basics ... ok
test index::tests::test_quantize ... ok
test optim::tests::test_refine_anng ... ok
test index::tests::test_multithreaded ... ok
test result: ok. 5 passed; 0 failed; 2 ignored; 0 measured; 0 filtered out; finished in 0.29s
Doc-tests ngt
running 2 tests
test src/lib.rs - (line 17) ... FAILED
test src/lib.rs - (line 37) ... FAILED
failures:
---- src/lib.rs - (line 17) stdout ----
Test executable failed (exit status: 127).
stderr:
/tmp/rustdoctest9cK9AQ/rust_out: error while loading shared libraries: libngt.so.1: cannot open shared object file: No such file or directory
---- src/lib.rs - (line 37) stdout ----
Test executable failed (exit status: 127).
stderr:
/tmp/rustdoctest5ep2IC/rust_out: error while loading shared libraries: libngt.so.1: cannot open shared object file: No such file or directory
failures:
src/lib.rs - (line 17)
src/lib.rs - (line 37)
test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.36s
error: test failed, to rerun pass '--doc'
Something is looking for libngt.so.1
. I don't have time to look further into this right now but I will try a bit later this evening.
oh nvm I see I need to add a feature.
Perfect, this works:
$ cargo test --features static
Thanks again!
The idea
Looking in
/lib
after a build, I seelibngt.a
:So I was wondering whether it would be possible to link ngt statically. This would remove the need to have to put
libngt.so
in a place where executables can find it.Naively, I changed a line in
build.rs
from this:to this:
This fails
After making the change to
build.rs
, this error occurs when runningcargo build
:Further investigation
Checking the file sizes of the ngt build artifacts:
We see
libngt.a
is ~ 56 M. Checking for therlib
libraries produced by rust:We see that
libngt_sys-88de9e97cd094267.rlib
size is around ~ 57 MB, suggesting thatlibngt.a
has been linked into it?That's as far as I can go for now, but hopefully we can figure out a way to link ngt statically?