flann-lib / flann

Fast Library for Approximate Nearest Neighbors
http://people.cs.ubc.ca/~mariusm/flann
Other
2.25k stars 648 forks source link

undefined reference to LZ4 for flann 1.8.5 or later #384

Open wanghaiqiangk opened 6 years ago

wanghaiqiangk commented 6 years ago

I'm using the latest flann to do knnSearch. So we have the codes

flann::Index<flann::L2<float>> index(...);
index.buildIndex();
index.knnSearch(...);

And I also use CMakeLists.txt to build the project. Now when I try to make, it gives errors about undefined reference to LZ4 stuffs

CMakeFiles/pano.dir/lib/feature.cpp.o: In function `flann::serialization::SaveArchive::initBlock()':
feature.cpp:(.text._ZN5flann13serialization11SaveArchive9initBlockEv[_ZN5flann13serialization11SaveArchive9initBlockEv]+0x47): undefined reference to `LZ4_resetStreamHC'
CMakeFiles/pano.dir/lib/feature.cpp.o: In function `flann::serialization::SaveArchive::flushBlock()':
feature.cpp:(.text._ZN5flann13serialization11SaveArchive10flushBlockEv[_ZN5flann13serialization11SaveArchive10flushBlockEv]+0x40): undefined reference to `LZ4_compress_HC_continue'
feature.cpp:(.text._ZN5flann13serialization11SaveArchive10flushBlockEv[_ZN5flann13serialization11SaveArchive10flushBlockEv]+0xdd): undefined reference to `LZ4_compress_HC_continue'
CMakeFiles/pano.dir/lib/feature.cpp.o: In function `flann::serialization::LoadArchive::decompressAndLoadV10(_IO_FILE*)':
feature.cpp:(.text._ZN5flann13serialization11LoadArchive20decompressAndLoadV10EP8_IO_FILE[_ZN5flann13serialization11LoadArchive20decompressAndLoadV10EP8_IO_FILE]+0xd0): undefined reference to `LZ4_decompress_safe'
CMakeFiles/pano.dir/lib/feature.cpp.o: In function `flann::serialization::LoadArchive::loadBlock(char*, unsigned long, _IO_FILE*)':
feature.cpp:(.text._ZN5flann13serialization11LoadArchive9loadBlockEPcmP8_IO_FILE[_ZN5flann13serialization11LoadArchive9loadBlockEPcmP8_IO_FILE]+0x41): undefined reference to `LZ4_decompress_safe_continue'
CMakeFiles/pano.dir/lib/feature.cpp.o: In function `flann::serialization::LoadArchive::initBlock(_IO_FILE*)':
feature.cpp:(.text._ZN5flann13serialization11LoadArchive9initBlockEP8_IO_FILE[_ZN5flann13serialization11LoadArchive9initBlockEP8_IO_FILE]+0xbf): undefined reference to `LZ4_setStreamDecode'
CMakeFiles/pano.dir/lib/feature.cpp.o: In function `flann::KDTreeSingleIndex >::saveIndex(_IO_FILE*)':
feature.cpp:(.text._ZN5flann17KDTreeSingleIndexINS_2L2IfEEE9saveIndexEP8_IO_FILE[_ZN5flann17KDTreeSingleIndexINS_2L2IfEEE9saveIndexEP8_IO_FILE]+0x6c): undefined reference to `LZ4_resetStreamHC'
CMakeFiles/pano.dir/lib/feature.cpp.o: In function `flann::LinearIndex >::saveIndex(_IO_FILE*)':
feature.cpp:(.text._ZN5flann11LinearIndexINS_2L2IfEEE9saveIndexEP8_IO_FILE[_ZN5flann11LinearIndexINS_2L2IfEEE9saveIndexEP8_IO_FILE]+0x61): undefined reference to `LZ4_resetStreamHC'
collect2: error: ld returned 1 exit status
make[2]: *** [pano] Error 1
make[1]: *** [CMakeFiles/pano.dir/all] Error 2
make: *** [all] Error 2

As what I know, it seems it can't find liblz4.so. However, it's located under /usr/lib/x86_64-linux-gnu/liblz4.so. So how to solve the problem? Currently, I can only use v1.8.4 to get around since it doesn't use lz4.

marijnfs commented 6 years ago

Did you have any progress on this issue?

wanghaiqiangk commented 6 years ago

@marijnfs Nah. I used older version which would work fine. You may try to check whether the liblz4.so is properly linked or modify CMakeLists.txt to manually link the library. I met other same problems and solved by this method. So probably you can give a try.

kheaactua commented 5 years ago

The trick for me seems to have been to also link against flann_s. I did this because if you look in src/CMakeLists.txt, the lz4 stuff is only included in C_SOURCES, which on Windows is only built into flann_s.

alvaroga91 commented 5 years ago

@kheaactua Could you post your exact changes, please? :) I'm having this exact issue while cross-compiling. Did you change FLANN's CMakeLists.txt?

Additionally, I found out this does happens with the examples so just compile without the BUILD_EXAMPLES option.

evaliyev commented 5 years ago

+1

jvmassaro commented 4 years ago

The problem is that the LZ4_LIBRARIES are never found. I created a patch to fix this but you would have to insert the location of your lz4 lib directory. The patched file is flann/src/cpp/CMakeLists.txt.

+message(STATUS "Finding LZ4 libraries") +find_library(LZ4_LIBRARIES NAMES liblz4.so HINTS "lz4/lib") +if(LZ4_LIBRARIES)