c++ - Why I cannot link this library? -


i'm trying compile flann_example.cpp flann library:

#include <flann/flann.hpp> #include <flann/io/hdf5.h>  #include <stdio.h>  using namespace flann;  int main(int argc, char** argv) {     int nn = 3;      matrix<float> dataset;     matrix<float> query;     load_from_file(dataset, "dataset.hdf5","dataset");     load_from_file(query, "dataset.hdf5","query");      matrix<int> indices(new int[query.rows*nn], query.rows, nn);     matrix<float> dists(new float[query.rows*nn], query.rows, nn);      // construct randomized kd-tree index using 4 kd-trees     index<l2<float> > index(dataset, flann::kdtreeindexparams(4));     index.buildindex();                                                                                                     // knn search, using 128 checks     index.knnsearch(query, indices, dists, nn, flann::searchparams(128));      flann::save_to_file(indices,"result.hdf5","result");      delete[] dataset.ptr();     delete[] query.ptr();     delete[] indices.ptr();     delete[] dists.ptr();      return 0; } 

and how try compile it:

g++ flann_example.cpp -i/usr/include/hdf5/serial -l/usr/lib/x86_64-linux-gnu/hdf5/serial/lib -l/usr/lib/x86_64-linux-gnu -lhdf5

but receive error:

/tmp/ccphatgt.o: in function `flann::serialization::savearchive::initblock()': flann_example.cpp:(.text._zn5flann13serialization11savearchive9initblockev[_zn5flann13serialization11savearchive9initblockev]+0xb9): undefined reference `lz4_resetstreamhc' /tmp/ccphatgt.o: in function `flann::serialization::savearchive::flushblock()': flann_example.cpp:(.text._zn5flann13serialization11savearchive10flushblockev[_zn5flann13serialization11savearchive10flushblockev]+0xc5): undefined reference `lz4_compress_hc_continue' flann_example.cpp:(.text._zn5flann13serialization11savearchive10flushblockev[_zn5flann13serialization11savearchive10flushblockev]+0x18c): undefined reference `lz4_compress_hc_continue' /tmp/ccphatgt.o: in function `flann::serialization::loadarchive::decompressandloadv10(_io_file*)': flann_example.cpp:(.text._zn5flann13serialization11loadarchive20decompressandloadv10ep8_io_file[_zn5flann13serialization11loadarchive20decompressandloadv10ep8_io_file]+0x225): undefined reference `lz4_decompress_safe' /tmp/ccphatgt.o: in function `flann::serialization::loadarchive::initblock(_io_file*)': flann_example.cpp:(.text._zn5flann13serialization11loadarchive9initblockep8_io_file[_zn5flann13serialization11loadarchive9initblockep8_io_file]+0x1f7): undefined reference `lz4_setstreamdecode' /tmp/ccphatgt.o: in function `flann::serialization::loadarchive::loadblock(char*, unsigned long, _io_file*)': flann_example.cpp:(.text._zn5flann13serialization11loadarchive9loadblockepcmp8_io_file[_zn5flann13serialization11loadarchive9loadblockepcmp8_io_file]+0xcc): undefined reference `lz4_decompress_safe_continue' collect2: error: ld returned 1 exit status 

then, since liblz4.so.1 in /usr/lib/x86_64-linux-gnu try this:

g++ flann_example.cpp -i/usr/include/hdf5/serial -l/usr/lib/x86_64-linux-gnu/hdf5/serial/lib -l/usr/lib/x86_64-linux-gnu -lhdf5 -llz4 

but:

/usr/bin/ld: cannot find -llz4 collect2: error: ld returned 1 exit status 

since liblz4.so not present in system, had to:

sudo apt-get install liblz4-dev

and then:

g++ flann_example.cpp -i/usr/include/hdf5/serial -l/usr/lib/x86_64-linux-gnu/hdf5/serial/lib -l/usr/lib/x86_64-linux-gnu -lhdf5 -llz4

worked.


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -