By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,458 Members | 1,215 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,458 IT Pros & Developers. It's quick & easy.

Compilation Error using ANN Approximate nearest neighbour library

P: n/a
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://v5o5jotqkgfu3btr91t7w5fhzedja...a/~m0f14/ANN.h
http://v5o5jotqkgfu3btr91t7w5fhzedja.../ann_sample.cc

Thanks for any help,
Travis
Jul 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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://v5o5jotqkgfu3btr91t7w5fhzedja...a/~m0f14/ANN.h
http://v5o5jotqkgfu3btr91t7w5fhzedja.../ann_sample.cc

V
Jul 22 '05 #2

P: n/a
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
kb******@gascad.at
Jul 22 '05 #3

P: n/a
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
kb******@gascad.at
Jul 22 '05 #4

P: n/a
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.
Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.