Compilation Error using ANN Approximate nearest neighbour library

T

Travis Stewart

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
 
V

Victor Bazarov

Travis said:
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
 
K

Karl Heinz Buchegger

Travis said:
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!
 
K

Karl Heinz Buchegger

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.
 
J

Joes Staal

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top