Closed ansjsun closed 4 years ago
Googling the error undefined reference to symbol '__gxx_personality_v0@@CXXABI_1.3'
reveals that this is caused by using the wrong std c++ library.
indeed, you are doing:
.cpp_link_stdlib(Some("faiss"))
but that's meant to replace the std library, not adding your own library. Try removing this line.
In order to link against faiss, the println line you added should be enough.
thanks for your replay, it is a grate project Now I take build.rs to this .
fn main() {
println!("cargo:rustc-link-lib=faiss");
println!("cargo:rustc-link-lib=stdc++");
cpp_build::Config::new().build("src/lib.rs");
}
or
fn main() {
println!("cargo:rustc-link-lib=faiss");
cpp_build::Config::new().build("src/lib.rs");
}
But I got
= note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/ansj/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/ansj/rustworksapce/hello/target/debug/deps/hello-0cbb6866c962d6f9.124ddisnfpos9lxo.rcgu.o" "/home/ansj/rustworksapce/hello/target/debug/deps/hello-0cbb6866c962d6f9.1jfqgosp5i347vli.rcgu.o" "/home/ansj/rustworksapce/hello/target/debug/deps/hello-0cbb6866c962d6f9.1q2rf3yhihppd9ph.rcgu.o" "/home/ansj/rustworksapce/hello/target/debug/deps/hello-0cbb6866c962d6f9.1xea4d17ghpmajud.rcgu.o" "/home/ansj/rustworksapce/hello/target/debug/deps/hello-0cbb6866c962d6f9.2ntpl1fawdwdj8ii.rcgu.o" "/home/ansj/rustworksapce/hello/target/debug/deps/hello-0cbb6866c962d6f9.390xravyzwl26gsi.rcgu.o" "/home/ansj/rustworksapce/hello/target/debug/deps/hello-0cbb6866c962d6f9.3iqzyypn67h4qgca.rcgu.o" "/home/ansj/rustworksapce/hello/target/debug/deps/hello-0cbb6866c962d6f9.oivq2zyp44xtbes.rcgu.o" "/home/ansj/rustworksapce/hello/target/debug/deps/hello-0cbb6866c962d6f9.qy14ec1jhemw9ts.rcgu.o" "/home/ansj/rustworksapce/hello/target/debug/deps/hello-0cbb6866c962d6f9.y4e2jgb9n92r35y.rcgu.o" "-o" "/home/ansj/rustworksapce/hello/target/debug/deps/hello-0cbb6866c962d6f9" "/home/ansj/rustworksapce/hello/target/debug/deps/hello-0cbb6866c962d6f9.27qv7ws3oh1qrdwh.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "/home/ansj/rustworksapce/hello/target/debug/deps" "-L" "/home/ansj/rustworksapce/hello/target/debug/build/hello-64c7196ef49206ed/out" "-L" "/home/ansj/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-lfaiss" "-Wl,-Bstatic" "-Wl,--whole-archive" "-lrust_cpp_generated" "-Wl,--no-whole-archive" "-Wl,-Bdynamic" "-lstdc++" "-Wl,-Bstatic" "/home/ansj/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libtest-a8145b8d68165abb.rlib" "/home/ansj/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libterm-4ca06a016781ab88.rlib" "/home/ansj/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgetopts-db92cd117318c238.rlib" "/home/ansj/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunicode_width-c201880a4dbbde6b.rlib" "/home/ansj/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_std-d419b37ed18b6a41.rlib" "/home/ansj/rustworksapce/hello/target/debug/deps/libcpp-f93b0ae0996157b2.rlib" "-Wl,--start-group" "/home/ansj/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-9d59e25e2eb2384d.rlib" "/home/ansj/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-4affccee0db9d60e.rlib" "/home/ansj/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-cd6b495608e342d1.rlib" "/home/ansj/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-347d88a586b28b4c.rlib" "/home/ansj/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace-46f3dc0b263b900a.rlib" "/home/ansj/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace_sys-6789aa6fbcfdf14c.rlib" "/home/ansj/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-9f9436f1ab051941.rlib" "/home/ansj/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-ad8ec269e6d86d01.rlib" "/home/ansj/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-3699f95d33475c27.rlib" "/home/ansj/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-fe798441633702e1.rlib" "/home/ansj/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-979288990efe6065.rlib" "/home/ansj/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-2181f1e1dd7399d7.rlib" "/home/ansj/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-b8952fd765001238.rlib" "-Wl,--end-group" "/home/ansj/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-e99fedbd2b621435.rlib" "-Wl,-Bdynamic" "-ldl" "-lrt" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-lutil"
= note: /home/ansj/rustworksapce/hello/target/debug/build/hello-64c7196ef49206ed/out/librust_cpp_generated.a(cpp_closures.o):在函数‘bcd()’中:
/home/ansj/rustworksapce/hello/src/lib.rs:42:对‘faiss::MultiIndexQuantizer::MultiIndexQuantizer(int, unsigned long, unsigned long)’未定义的引用
/home/ansj/rustworksapce/hello/target/debug/build/hello-64c7196ef49206ed/out/librust_cpp_generated.a(cpp_closures.o):在函数‘faiss::MultiIndexQuantizer::~MultiIndexQuantizer()’中:
/usr/local/include/faiss/IndexPQ.h:147:对‘vtable for faiss::MultiIndexQuantizer’未定义的引用
/usr/local/include/faiss/IndexPQ.h:147:对‘faiss::Index::~Index()’未定义的引用
take build.rs to
fn main() {
cpp_build::Config::new().build("src/lib.rs");
println!("cargo:rustc-link-lib=static=faiss");
}
I got
/home/ansj/src/faiss/utils/hamming.cpp:334:对‘omp_get_num_threads’未定义的引用
/home/ansj/src/faiss/utils/hamming.cpp:334:对‘omp_get_thread_num’未定义的引用
//usr/local/lib/libfaiss.a(hamming.o):在函数‘void faiss::hammings_knn_mc<faiss::HammingComputer8>(int, unsigned char const*, unsigned char const*, unsigned long, unsigned long, unsigned long, int*, long*) [clone ._omp_fn.10]’中:
/home/ansj/src/faiss/utils/hamming.cpp:334:对‘omp_get_num_threads’未定义的引用
/home/ansj/src/faiss/utils/hamming.cpp:334:对‘omp_get_thread_num’未定义的引用
//usr/local/lib/libfaiss.a(hamming.o):在函数‘void faiss::hammings_knn_mc<faiss::HammingComputer16>(int, unsigned char const*, unsigned char const*, unsigned long, unsigned long, unsigned long, int*, long*) [clone ._omp_fn.11]’中:
/home/ansj/src/faiss/utils/hamming.cpp:334:对‘omp_get_num_threads’未定义的引用
/home/ansj/src/faiss/utils/hamming.cpp:334:对‘omp_get_thread_num’未定义的引用
//usr/local/lib/libfaiss.a(hamming.o):在函数‘void faiss::hammings_knn_mc<faiss::HammingComputer32>(int, unsigned char const*, unsigned char const*, unsigned long, unsigned long, unsigned long, int*, long*) [clone ._omp_fn.12]’中:
/home/ansj/src/faiss/utils/hamming.cpp:334:对‘omp_get_num_threads’未定义的引用
/home/ansj/src/faiss/utils/hamming.cpp:334:对‘omp_get_thread_num’未定义的引用
//usr/local/lib/libfaiss.a(hamming.o):在函数‘void faiss::hammings_knn_mc<faiss::HammingComputerM8>(int, unsigned char const*, unsigned char const*, unsigned long, unsigned long, unsigned long, int*, long*) [clone ._omp_fn.13]’中:
/home/ansj/src/faiss/utils/hamming.cpp:334:对‘omp_get_num_threads’未定义的引用
/home/ansj/src/faiss/utils/hamming.cpp:334:对‘omp_get_thread_num’未定义的引用
//usr/local/lib/libfaiss.a(hamming.o):在函数‘void faiss::hammings_knn_mc<faiss::HammingComputerDefault>(int, unsigned char const*, unsigned char const*, unsigned long, unsigned long, unsigned long, int*, long*) [clone ._omp_fn.14]’中:
/home/ansj/src/faiss/utils/hamming.cpp:334:对‘omp_get_num_threads’未定义的引用
/home/ansj/src/faiss/utils/hamming.cpp:334:对‘omp_get_thread_num’未定义的引用
//usr/local/lib/libfaiss.a(hamming.o):在函数‘void faiss::hamming_range_search_template<faiss::HammingComputer32>(unsigned char const*, unsigned char const*, unsigned long, unsigned long, int, unsigned long, faiss::RangeSearchResult*) [clone ._omp_fn.18]’中:
/home/ansj/src/faiss/utils/hamming.cpp:653:对‘omp_get_num_threads’未定义的引用
/home/ansj/src/faiss/utils/hamming.cpp:653:对‘omp_get_thread_num’未定义的引用
/home/ansj/src/faiss/utils/hamming.cpp:661:对‘GOMP_barrier’未定义的引用
//usr/local/lib/libfaiss.a(hamming.o):在函数‘void faiss::hamming_range_search_template<faiss::HammingComputerDefault>(unsigned char const*, unsigned char const*, unsigned long, unsigned long, int, unsigned long, faiss::RangeSearchResult*) [clone ._omp_fn.20]’中:
/home/ansj/src/faiss/utils/hamming.cpp:653:对‘omp_get_num_threads’未定义的引用
/home/ansj/src/faiss/utils/hamming.cpp:653:对‘omp_get_thread_num’未定义的引用
/home/ansj/src/faiss/utils/hamming.cpp:661:对‘GOMP_barrier’未定义的引用
//usr/local/lib/libfaiss.a(hamming.o):在函数‘void faiss::hamming_range_search_template<faiss::HammingComputer4>(unsigned char const*, unsigned char const*, unsigned long, unsigned long, int, unsigned long, faiss::RangeSearchResult*) [clone ._omp_fn.15]’中:
/home/ansj/src/faiss/utils/hamming.cpp:653:对‘omp_get_num_threads’未定义的引用
/home/ansj/src/faiss/utils/hamming.cpp:653:对‘omp_get_thread_num’未定义的引用
/home/ansj/src/faiss/utils/hamming.cpp:661:对‘GOMP_barrier’未定义的引用
//usr/local/lib/libfaiss.a(hamming.o):在函数‘void faiss::hamming_range_search_template<faiss::HammingComputer8>(unsigned char const*, unsigned char const*, unsigned long, unsigned long, int, unsigned long, faiss::RangeSearchResult*) [clone ._omp_fn.16]’中:
/home/ansj/src/faiss/utils/hamming.cpp:653:对‘omp_get_num_threads’未定义的引用
/home/ansj/src/faiss/utils/hamming.cpp:653:对‘omp_get_thread_num’未定义的引用
/home/ansj/src/faiss/utils/hamming.cpp:661:对‘GOMP_barrier’未定义的引用
//usr/local/lib/libfaiss.a(hamming.o):在函数‘void faiss::hamming_range_search_template<faiss::HammingComputer16>(unsigned char const*, unsigned char const*, unsigned long, unsigned long, int, unsigned long, faiss::RangeSearchResult*) [clone ._omp_fn.17]’中:
/home/ansj/src/faiss/utils/hamming.cpp:653:对‘omp_get_num_threads’未定义的引用
/home/ansj/src/faiss/utils/hamming.cpp:653:对‘omp_get_thread_num’未定义的引用
/home/ansj/src/faiss/utils/hamming.cpp:661:对‘GOMP_barrier’未定义的引用
//usr/local/lib/libfaiss.a(hamming.o):在函数‘void faiss::hamming_range_search_template<faiss::HammingComputerM8>(unsigned char const*, unsigned char const*, unsigned long, unsigned long, int, unsigned long, faiss::RangeSearchResult*) [clone ._omp_fn.19]’中:
/home/ansj/src/faiss/utils/hamming.cpp:653:对‘omp_get_num_threads’未定义的引用
/home/ansj/src/faiss/utils/hamming.cpp:653:对‘omp_get_thread_num’未定义的引用
/home/ansj/src/faiss/utils/hamming.cpp:661:对‘GOMP_barrier’未定义的引用
//usr/local/lib/libfaiss.a(hamming.o):在函数‘void faiss::hammings_knn_hc<faiss::HammingComputer4>(int, faiss::HeapArray<faiss::CMax<int, long> >*, unsigned char const*, unsigned char const*, unsigned long, bool, bool) [clone ._omp_fn.3]’中:
/home/ansj/src/faiss/utils/hamming.cpp:282:对‘omp_get_num_threads’未定义的引用
/home/ansj/src/faiss/utils/hamming.cpp:282:对‘omp_get_thread_num’未定义的引用
//usr/local/lib/libfaiss.a(hamming.o):在函数‘void faiss::hammings_knn_hc<faiss::HammingComputer16>(int, faiss::HeapArray<faiss::CMax<int, long> >*, unsigned char const*, unsigned char const*, unsigned long, bool, bool) [clone ._omp_fn.5]’中:
/home/ansj/src/faiss/utils/hamming.cpp:282:对‘omp_get_num_threads’未定义的引用
/home/ansj/src/faiss/utils/hamming.cpp:282:对‘omp_get_thread_num’未定义的引用
//usr/local/lib/libfaiss.a(hamming.o):在函数‘void faiss::hammings_knn_hc<faiss::HammingComputerM8>(int, faiss::HeapArray<faiss::CMax<int, long> >*, unsigned char const*, unsigned char const*, unsigned long, bool, bool) [clone ._omp_fn.7]’中:
/home/ansj/src/faiss/utils/hamming.cpp:282:对‘omp_get_num_threads’未定义的引用
/home/ansj/src/faiss/utils/hamming.cpp:282:对‘omp_get_thread_num’未定义的引用
//usr/local/lib/libfaiss.a(hamming.o):在函数‘void faiss::hammings_knn_hc<faiss::HammingComputer32>(int, faiss::HeapArray<faiss::CMax<int, long> >*, unsigned char const*, unsigned char const*, unsigned long, bool, bool) [clone ._omp_fn.6]’中:
/home/ansj/src/faiss/utils/hamming.cpp:282:对‘omp_get_num_threads’未定义的引用
/home/ansj/src/faiss/utils/hamming.cpp:282:对‘omp_get_thread_num’未定义的引用
//usr/local/lib/libfaiss.a(hamming.o):在函数‘faiss::hammings_knn_hc_1(faiss::HeapArray<faiss::CMax<int, long> >*, unsigned long const*, unsigned long const*, unsigned long, bool, bool) [clone ._omp_fn.4]’中:
/home/ansj/src/faiss/utils/hamming.cpp:382:对‘omp_get_num_threads’未定义的引用
/home/ansj/src/faiss/utils/hamming.cpp:382:对‘omp_get_thread_num’未定义的引用
//usr/local/lib/libfaiss.a(hamming.o):在函数‘void faiss::hammings_knn_hc<faiss::HammingComputerDefault>(int, faiss::HeapArray<faiss::CMax<int, long> >*, unsigned char const*, unsigned char const*, unsigned long, bool, bool) [clone ._omp_fn.8]’中:
/home/ansj/src/faiss/utils/hamming.cpp:283:对‘omp_get_num_threads’未定义的引用
/home/ansj/src/faiss/utils/hamming.cpp:283:对‘omp_get_thread_num’未定义的引用
//usr/local/lib/libfaiss.a(hamming.o):在函数‘faiss::generalized_hammings_knn_hc(faiss::HeapArray<faiss::CMax<int, long> >*, unsigned char const*, unsigned char const*, unsigned long, unsigned long, int) [clone ._omp_fn.21]’中:
/home/ansj/src/faiss/utils/hamming.cpp:840:对‘omp_get_num_threads’未定义的引用
/home/ansj/src/faiss/utils/hamming.cpp:840:对‘omp_get_thread_num’未定义的引用
//usr/local/lib/libfaiss.a(hamming.o):在函数‘faiss::fvecs2bitvecs(float const*, unsigned char*, unsigned long, unsigned long) [clone ._omp_fn.0]’中:
/home/ansj/src/faiss/utils/hamming.cpp:437:对‘omp_get_num_threads’未定义的引用
/home/ansj/src/faiss/utils/hamming.cpp:437:对‘omp_get_thread_num’未定义的引用
//usr/local/lib/libfaiss.a(hamming.o):在函数‘faiss::fvecs2bitvecs(float const*, unsigned char*, unsigned long, unsigned long)’中:
/home/ansj/src/faiss/utils/hamming.cpp:436:对‘GOMP_parallel’未定义的引用
//usr/local/lib/libfaiss.a(hamming.o):在函数‘faiss::bitvecs2fvecs(unsigned char const*, float*, unsigned long, unsigned long)’中:
/home/ansj/src/faiss/utils/hamming.cpp:450:对‘GOMP_parallel’未定义的引用
//usr/local/lib/libfaiss.a(hamming.o):在函数‘faiss::bitvec_shuffle(unsigned long, unsigned long, unsigned long, int const*, unsigned char const*, unsigned char*)’中:
/home/ansj/src/faiss/utils/hamming.cpp:499:对‘GOMP_parallel’未定义的引用
//usr/local/lib/libfaiss.a(hamming.o):在函数‘hammings_knn_hc<faiss::HammingComputer32>’中:
/home/ansj/src/faiss/utils/hamming.cpp:282:对‘GOMP_parallel’未定义的引用
//usr/local/lib/libfaiss.a(hamming.o):在函数‘hammings_knn_hc<faiss::HammingComputer16>’中:
/home/ansj/src/faiss/utils/hamming.cpp:282:对‘GOMP_parallel’未定义的引用
//usr/local/lib/libfaiss.a(hamming.o):/home/ansj/src/faiss/utils/hamming.cpp:282: 跟着更多未定义的参考到 GOMP_parallel
Looks like you also need to link against omp, and maybe some other libraries (using println)
thx very mutch
take
println!("cargo:rustc-link-lib=dylib=omp");
println!("cargo:rustc-link-lib=dylib=faiss");
cpp_build::Config::new().build("src/example.rs");
work by mac os .. grate project ++
I make and install faiss in system.
I compile by g++ is ok
but use rust -cpp, has fail
my code is"
build.rs
lib.rs