[Linker error] undefined reference to ...

Hello,

Apologies if this is something simple, I'm very much a beginner.
I'm trying to include in a C++ program a package designed by somebody else, and keep getting the following error:
[Linker error] undefined reference to `_imp___Z11annAllocPtsii'

I think this is something to do with including the library that came with the package, which I've attempted to do with the following command in the linker command line:

-L "ANN.lib"

Is this not the correct way to include a library?

*edit* (The code aims to read data from a file into an array of a bespoke type 'ANNpointArray ')

I'm not sure how helpful it will be, but to be thorough here is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <fstream>
#include <string>
#include "ANN.h"
// http://www.cs.umd.edu/~mount/ANN/

using namespace std;
main( int argc,      // Number of strings in array argv
          char *argv[],   // Array of command-line argument strings
          char *envp[] )
{
          string line;
          string FileName;
          int D, N;
          int i, h;
          ANNpointArray dataPts;
          if(argc!=4)
                 {fprintf(stderr, "\nProblem with input");}
          
              FileName=argv[1];
              D=atoi(argv[2]);
              N=atoi(argv[3]);
              
              dataPts =  annAllocPts(
                                      N, //  number  of  points
                                      D); //  dimension
             
             ifstream myfile (FileName.c_str());
             
             for (i=0; i<N; ++i)
                 {
                 for (h=0; h<D; ++h)
                     {
                     myfile>>dataPts[i][h];
                     }
                 }
          return 0;
}
Last edited on
I think this is something to do with including the library that came with the package, which I've attempted to do with the following command in the linker command line:

-L "ANN.lib"

Is this not the correct way to include a library?


It sounds like you're using MSVS. I don't know the commandline jargon for it, but in the projects settings there is a list of libs you link to. Off the top of my head it's something like Project | Settings, then go the "Linker | Input" section and it's one of the first boxes on the type. You would type "ANN.lib" into that box.

If that's what you did, and it's still not working, then there's probalby some other lib you need to link to. I would check with the documentation of whatever lib you're using. Maybe go to its website and find a tutorial that shows how to get it set up properly.
Disch,

Thanks very much for that. I wasn't using MSVS, but have switched to it now and managed to add the library as per your instructions.

Thanks,
Matt
Topic archived. No new replies allowed.