yahoojapan / NGT

Nearest Neighbor Search with Neighborhood Graph and Tree for High-dimensional Data
Apache License 2.0
1.26k stars 115 forks source link

Facing issues with CPP Quick Start example #104

Closed shriyog closed 2 years ago

shriyog commented 2 years ago

Facing issues with the CPP example mentioned in https://github.com/yahoojapan/NGT/wiki/Cpp-Quick-Start

I've built & installed NGT as mentioned in https://github.com/yahoojapan/NGT#on-linux but getting following error while running the construct.cpp code given in the quick start.

g++ -std=c++11 -o construct -lngt construct.cpp 

/tmp/ccRBjxzo.o: In function `NGT::Index::Index(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)':
construct.cpp:(.text._ZN3NGT5IndexC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb[_ZN3NGT5IndexC5ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb]+0xc4): undefined reference to `NGT::Index::open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)'
/tmp/ccRBjxzo.o: In function `NGT::Index::createGraphAndTree(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, NGT::Property&, bool)':
construct.cpp:(.text._ZN3NGT5Index18createGraphAndTreeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS_8PropertyEb[_ZN3NGT5Index18createGraphAndTreeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS_8PropertyEb]+0x65): undefined reference to `NGT::Index::createGraphAndTree(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, NGT::Property&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long, bool)'
collect2: error: ld returned 1 exit status
masajiro commented 2 years ago

It seems that libngt is not installed properly. What is your OS? Can you run the command line tool "ngt"?

shriyog commented 2 years ago

Hey @masajiro — Thanks for replying! I've built this on Ubuntu 18.04.3 & can see the libraries installed

> ldconfig -p | grep libngt*
libngt.so.1 (libc6,x86-64) => /usr/local/lib/libngt.so.1
libngt.so (libc6,x86-64) => /usr/local/lib/libngt.so
libnghttp2.so.14 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libnghttp2.so.14

Also, I can't get ngt cli working

> ngt --help
ngt: symbol lookup error: ngt: undefined symbol: _ZN3NGT7Command6searchERNS_5IndexERNS0_15SearchParameterERSiRSo

I had tried setting this up locally on MacOS - the ngt cli works but can't get the cpp examples running.

masajiro commented 2 years ago

I cannot reproduce your situation. Could you run the commands below?

$ ldd `which ngt`|grep ngt
        libngt.so.1 => /usr/local/lib/libngt.so.1 (0x00007fc387bad000)

$ c++filt _ZN3NGT7Command6searchERNS_5IndexERNS0_15SearchParameterERSiRSo
NGT::Command::search(NGT::Index&, NGT::Command::SearchParameter&, std::basic_istream<char, std::char_traits<char> >&, std::basic_ostream<char, std::char_traits<char> >&)

$ nm /usr/local/lib/libngt.so.1.* | c++filt | grep NGT::Command::search
0000000000061bb0 T NGT::Command::search(NGT::Args&)
000000000005e090 T NGT::Command::search(NGT::Index&, NGT::Command::SearchParameters&, std::basic_istream<char, std::char_traits<char> >&, std::basic_ostream<char, std::char_traits<char> >&)
shriyog commented 2 years ago

@masajiro Here's my output

$ ldd `which ngt`|grep ngt
libngt.so.1 => /usr/local/lib/libngt.so.1 (0x00007fd46fb16000)

$ c++filt _ZN3NGT7Command6searchERNS_5IndexERNS0_15SearchParameterERSiRSo
NGT::Command::search(NGT::Index&, NGT::Command::SearchParameter&, std::basic_istream<char, std::char_traits<char> >&, std::basic_ostream<char, std::char_traits<char> >&)

$ nm /usr/local/lib/libngt.so.1.* | c++filt | grep NGT::Command::search
000000000005a3e0 T NGT::Command::search(NGT::Args&)
00000000000566e0 T NGT::Command::search(NGT::Index&, NGT::Command::SearchParameters&, std::basic_istream<char, std::char_traits<char> >&, std::basic_ostream<char, std::char_traits<char> >&)
0000000000040fd0 T NGT::Command::search(NGT::Args&)
000000000003e620 T NGT::Command::search(NGT::Index&, NGT::Command::SearchParameter&, std::basic_istream<char, std::char_traits<char> >&, std::basic_ostream<char, std::char_traits<char> >&)
masajiro commented 2 years ago

I think that there are 2 versions of libngt from your output. "ngt" of v1.12 refers libngt of v1.13. You may want to build and install the latest NGT (v1.13.8). Then, please make sure that you use the reinstalled commands, libraries and headers .

shriyog commented 2 years ago

@masajiro I've built & installed the latest release you mentioned (v1.13.8) on a new Linux machine. Can see the commands are showing same results as you mentioned.

$ ldd `which ngt`|grep ngt
libngt.so.1 => /usr/local/lib/libngt.so.1 (0x00007f591b4fc000)

$ c++filt _ZN3NGT7Command6searchERNS_5IndexERNS0_15SearchParameterERSiRSo
NGT::Command::search(NGT::Index&, NGT::Command::SearchParameter&, std::basic_istream<char, std::char_traits<char> >&, std::basic_ostream<char, std::char_traits<char> >&)

$ nm /usr/local/lib/libngt.so.1.* | c++filt | grep NGT::Command::search
000000000005c8b0 T NGT::Command::search(NGT::Args&)
0000000000058b40 T NGT::Command::search(NGT::Index&, NGT::Command::SearchParameters&, std::basic_istream<char, std::char_traits<char> >&, std::basic_ostream<char, std::char_traits<char> >&)

I was able to get the NGT CLI working this time but the CPP sample code is giving the same error again.

$ g++ -std=c++11 -o construct -lngt construct.cpp 
/tmp/cc4CgJRQ.o: In function `NGT::Index::Index(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)':
construct.cpp:(.text._ZN3NGT5IndexC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb[_ZN3NGT5IndexC5ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb]+0xc4): undefined reference to `NGT::Index::open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)'
/tmp/cc4CgJRQ.o: In function `NGT::Index::createGraphAndTree(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, NGT::Property&, bool)':
construct.cpp:(.text._ZN3NGT5Index18createGraphAndTreeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS_8PropertyEb[_ZN3NGT5Index18createGraphAndTreeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS_8PropertyEb]+0x65): undefined reference to `NGT::Index::createGraphAndTree(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, NGT::Property&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long, bool)'

I think the error shows a difference in NGT::Index::createGraphAndTree arguments - an extra string & unsigned long. Is the sample code mentioned in Wiki or anything under samples folder working for you?

masajiro commented 2 years ago

How about this.

g++ -std=c++11 -o construct construct.cpp -lngt
shriyog commented 2 years ago

@masajiro Yes, this worked! Thank you for all your help.