flann-lib / flann

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

Linking error while compiling a GPU example #468

Open MDurgaKeerthi opened 3 years ago

MDurgaKeerthi commented 3 years ago

I am not able to compile the following example that uses the GPU version of Flann. I get the following linking error. Any help is appreciated?

g++ flann_example.cpp -o flann_example_cpp -I../src/cpp/  -lhdf5 -I/usr/include/hdf5/serial/ -L/usr/lib/x86_64-linux-gnu/hdf5/serial/ -lhdf5_cpp  --std=c++11 -L/usr/lib/x86_64-linux-gnu/ -llz4 
/tmp/ccok6xop.o: In function `flann::KDTreeCuda3dIndex<flann::L2_Simple<float> >::~KDTreeCuda3dIndex()':
flann_example.cpp:(.text._ZN5flann17KDTreeCuda3dIndexINS_9L2_SimpleIfEEED2Ev[_ZN5flann17KDTreeCuda3dIndexINS_9L2_SimpleIfEEED5Ev]+0x41): undefined reference to `flann::KDTreeCuda3dIndex<flann::L2_Simple<float> >::clearGpuBuffers()'
/tmp/ccok6xop.o: In function `flann::KDTreeCuda3dIndex<flann::L2_Simple<float> >::buildIndex()':
flann_example.cpp:(.text._ZN5flann17KDTreeCuda3dIndexINS_9L2_SimpleIfEEE10buildIndexEv[_ZN5flann17KDTreeCuda3dIndexINS_9L2_SimpleIfEEE10buildIndexEv]+0xad): undefined reference to `flann::KDTreeCuda3dIndex<flann::L2_Simple<float> >::uploadTreeToGpu()'
collect2: error: ld returned 1 exit status

flann_example.cpp

    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 an randomized kd-tree index using 4 kd-trees
    // flann::KDTreeCuda3dIndex<flann::L2<float> > tmpGPUIndex(dataset, flann::KDTreeCuda3dIndexParams());
    flann::Index<L2_Simple<float> > tmpGPUIndex(dataset, flann::KDTreeCuda3dIndexParams());
    tmpGPUIndex.buildIndex();                                                                                          

    // do a knn search, using 128 checks
    flann::SearchParams tmpSearchParams;
    tmpSearchParams.checks = 8;
    tmpSearchParams.sorted = false;
    tmpGPUIndex.knnSearch(query, indices, dists, nn, tmpSearchParams);   
MDurgaKeerthi commented 3 years ago

Update- I changed the flag -dc to -c, it compiles but when I try to run ./flann_example_cpp, it gives me this error.

bash: ./flann_example_cpp: cannot execute binary file: Exec format error

Any idea what's going on?