Compilation Error using ANN Approximate nearest neighbour library

Discussion in 'C++' started by Travis Stewart, Jun 9, 2004.

  1. Hi,
    I am not very familiar with C++ so the problems I am having might be
    simple and I just cannot see them or I am totally unaware of why something
    would be incorrect. Anyway, I'm using the ANN approximate nearest
    neighbour libraries written by David Mount and Sunil Arya. In the ANN.h
    file there is a comment describing how the data types used to represent
    the coordinates and distances between points can be modified by the user.
    For my use of library it would be most convientent to use a float instead
    of the default double type. When I compile the program initially with the
    original settings I do not get errors, but when I modify the header file
    for the float type I get the error:

    [stewart@samples]$ g++ ann_sample.cc -I/home/stewart/ANN/include
    -L/home/stewart/ANN/lib -lANN -Wno-deprecated
    /tmp/ccrhNdym.o(.text+0x123): In function `main':
    : undefined reference to `annAllocPt(int, float)'
    /tmp/ccrhNdym.o(.text+0x1e0): In function `main':
    : undefined reference to `ANNkd_tree::ANNkd_tree[in-charge](float**, int,
    : int, i
    nt, ANNsplitRule)'
    collect2: ld returned 1 exit status

    The program I am using and the modified header file (the types of
    ANNcoord and ANNdist are now float, and ANN_DIST_INF is now MAXFLOAT) are
    rather long so I have links to each.

    http://v5o5jotqkgfu3btr91t7w5fhzedjaoaz8igl.unbf.ca/~m0f14/ANN.h
    http://v5o5jotqkgfu3btr91t7w5fhzedjaoaz8igl.unbf.ca/~m0f14/ann_sample.cc

    Thanks for any help,
    Travis
    Travis Stewart, Jun 9, 2004
    #1
    1. Advertising

  2. Travis Stewart wrote:
    > I am not very familiar with C++ so the problems I am having might be
    > simple and I just cannot see them or I am totally unaware of why something
    > would be incorrect. Anyway, I'm using the ANN approximate nearest
    > neighbour libraries written by David Mount and Sunil Arya. In the ANN.h
    > file there is a comment describing how the data types used to represent
    > the coordinates and distances between points can be modified by the user.
    > For my use of library it would be most convientent to use a float instead
    > of the default double type. When I compile the program initially with the
    > original settings I do not get errors, but when I modify the header file
    > for the float type


    Don't. The library needs 'double', you have to give it double. Who in
    the world told you that you could modify the header without modifying the
    library itself?

    > I get the error:
    >
    > [stewart@samples]$ g++ ann_sample.cc -I/home/stewart/ANN/include
    > -L/home/stewart/ANN/lib -lANN -Wno-deprecated
    > /tmp/ccrhNdym.o(.text+0x123): In function `main':
    > : undefined reference to `annAllocPt(int, float)'
    > /tmp/ccrhNdym.o(.text+0x1e0): In function `main':
    > : undefined reference to `ANNkd_tree::ANNkd_tree[in-charge](float**, int,
    > : int, i
    > nt, ANNsplitRule)'
    > collect2: ld returned 1 exit status
    >
    > The program I am using and the modified header file (the types of
    > ANNcoord and ANNdist are now float, and ANN_DIST_INF is now MAXFLOAT) are
    > rather long so I have links to each.
    >
    > http://v5o5jotqkgfu3btr91t7w5fhzedjaoaz8igl.unbf.ca/~m0f14/ANN.h
    > http://v5o5jotqkgfu3btr91t7w5fhzedjaoaz8igl.unbf.ca/~m0f14/ann_sample.cc



    V
    Victor Bazarov, Jun 9, 2004
    #2
    1. Advertising

  3. Travis Stewart wrote:
    >
    > Hi,
    > I am not very familiar with C++ so the problems I am having might be
    > simple and I just cannot see them or I am totally unaware of why something
    > would be incorrect. Anyway, I'm using the ANN approximate nearest
    > neighbour libraries written by David Mount and Sunil Arya. In the ANN.h
    > file there is a comment describing how the data types used to represent
    > the coordinates and distances between points can be modified by the user.
    > For my use of library it would be most convientent to use a float instead
    > of the default double type.


    Note that in technical applications, float is almost never the
    data type one wants to use except in very rare circumstances and
    only if the programmer knows what he is doing and is ready to fight
    all the problems that come with the reduces precission of float.

    > When I compile the program initially with the
    > original settings I do not get errors, but when I modify the header file
    > for the float type I get the error:
    >
    > [stewart@samples]$ g++ ann_sample.cc -I/home/stewart/ANN/include
    > -L/home/stewart/ANN/lib -lANN -Wno-deprecated
    > /tmp/ccrhNdym.o(.text+0x123): In function `main':
    > : undefined reference to `annAllocPt(int, float)'


    The linker is telling you, that one of the prototypes
    announced a function called annAllocPt which
    takes an int and a float as arguments.
    But when the linker searched for that function it could not find
    it.

    Since the whole thing links correctly when you use double, I bet
    that there is a function annAllocPt which takes an int and
    a double.

    I suspect the original programmer to have made a mistake:
    In the Ann.h file he introduced the prototype

    ANNpoint annAllocPt(
    int dim, // dimension
    ANNcoord c = 0); // coordinate value (all equal)

    But when implementing the function he did:

    ANNpoint annAllocPt( int dim, double c )
    {
    // code goes here
    }

    Since the original program author did never use float for ANNcoord the
    error went by undetected.

    Search for the functions implementation and verify if my theory holds.


    > /tmp/ccrhNdym.o(.text+0x1e0): In function `main':
    > : undefined reference to `ANNkd_tree::ANNkd_tree[in-charge](float**, int,
    > : int, i
    > nt, ANNsplitRule)'
    > collect2: ld returned 1 exit status


    I guess this can be explained in pretty much the same way.


    Since I think this *is* important, I would like to repeat one thing:
    If you don't know what bag of worms you probably open by changing
    double to float and have the knowledge of fighting against those
    worms, don't use float!
    I don't know you in person and I don't know if you are a newbie or not.
    But if you are a newbie: don't use float!

    --
    Karl Heinz Buchegger
    Karl Heinz Buchegger, Jun 9, 2004
    #3
  4. Karl Heinz Buchegger wrote:
    >


    Ooops. I missed the fact, that you link against a prebuilt
    library.
    You can't do what you want. The library is cmopiled
    for double, you have to use it that way.

    The situation would be different, if you have the source
    code and build the library on your own.

    --
    Karl Heinz Buchegger
    Karl Heinz Buchegger, Jun 9, 2004
    #4
  5. Travis Stewart

    Joes Staal Guest

    As Karl pointed out, you need a library that is built with the float
    option. I have been using the library of Arya and Mount for quite a
    while and compiled it with the float option turned on. It works really
    well (no problem in using float instead of double).
    So, recompile the library and you should be fine.

    Joes.
    Joes Staal, Jun 9, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Eggert

    Can you approximate subranges in C?

    Paul Eggert, Jul 4, 2003, in forum: C Programming
    Replies:
    9
    Views:
    403
    Clive D. W. Feather
    Jul 7, 2003
  2. Istvan Albert
    Replies:
    0
    Views:
    437
    Istvan Albert
    Aug 31, 2003
  3. Nick Leverton
    Replies:
    2
    Views:
    587
    Nick Leverton
    Dec 5, 2008
  4. Albert

    Approximate integer square roots

    Albert, Jan 30, 2009, in forum: C Programming
    Replies:
    4
    Views:
    502
    Eric Sosman
    Jan 30, 2009
  5. PerlFAQ Server

    FAQ 6.16 How can I do approximate matching?

    PerlFAQ Server, Feb 28, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    87
    PerlFAQ Server
    Feb 28, 2011
Loading...

Share This Page