Thread: recursive pathfinding vs linker

  1. #1
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179

    recursive pathfinding vs linker

    First off, I'm having trouble with c++ in a function I intend to use in a game and it won't compile on linux, so I wasn't really sure where to post this. I put together a little console demo of my pathfinder, only it gets these errors:
    /tmp/ccn7Uc0Z.o(.text+0x16f): In function `main':
    : undefined reference to `map_t::~map_t [in-charge]()'
    /tmp/ccn7Uc0Z.o(.text+0x195): In function `main':
    : undefined reference to `map_t::~map_t [in-charge]()'
    /tmp/ccn7Uc0Z.o(.text+0x266): In function `printpath(map_t&, path_t&)':
    : undefined reference to `map_t::get(int, int)'
    /tmp/ccn7Uc0Z.o(.text+0x509): In function `findpath(map_t&, path_t)':
    : undefined reference to `map_t::get(int, int)'
    collect2: ld returned 1 exit status
    I can't even begin to decipher this. Does it mean that my #includes aren't set up right or I need to redefine some functions in the map_t class or what?
    I'm using g++ on redhat 9, here's the code it has a problem with:
    Code:
    int main() {
      path_t path;
      map_t map("default.map");
      cout << "STARTING!\n";
      path = findpath(map,path);
      cout << "DONE!\n";
      printpath(map,path);
      return 0;
    }
    
    void printpath(map_t& map,path_t& path) {
      char **disp = new char*[map.w];
      int i, j, k;
      for (i = 0; i < map.w; ++i)
        disp[i] = new char[map.h];
      for (i = 0; i < map.w; ++i)
        for (j = 0; j < map.h; ++j) {
          disp[i][j] = map.get(i,j);
          for (k = 0; k < path.nummove; ++k)
    	if (path.getmove(k)->x == i &&
    	    path.getmove(k)->y == j)
    	  disp[i][j] = '*';
        }
      disp[map.destx][map.desty] = 'X';
      for (i = 0; i < map.w; ++i) {
        for (j = 0; j < map.h; ++j)
          cout << disp[i][j];
        cout << endl;
        delete [] disp[i];
      }
      delete [] disp;
    }
    
    path_t findpath(map_t& map, path_t path) {
      if (path.lastmove()->x == map.destx &&
          path.lastmove()->y == map.desty) {
        return path;
      }
      move_t testmove[4];
      bool valid[4];
      int numvalid = 0, min = INT_MAX, minpos = -1;
      int i = 0, j = 0, dx, dy;
      for (dx = -1; dx <= 1; dx += 2)
        for (dy = -1; dy <= 1; dy += 2) {
          testmove[i].x = path.lastmove()->x + dx;
          testmove[i].y = path.lastmove()->y + dy;
          if (testmove[i].x >= 0 && testmove[i].x < map.w &&
    	  testmove[i].y >= 0 && testmove[i].y < map.h &&
    	  map.get(testmove[i].x,testmove[i].y == '0')) {
    	valid[i] = true;
    	++numvalid;
          }
          ++i;
        }
      path_t *testpath = new path_t[numvalid];
      for (i = 0; i < 4; ++i)
        if (valid[i]) {
          testpath[j].add(path);
          testpath[j].add(testmove[i]);
          testpath[j] = findpath(map,testpath[j]);
          if (testpath[j].nummove < min) {
    	min = testpath[j].nummove;
    	minpos = i;
          }
          ++j;
        }
      delete [] testpath;
      if (minpos == -1) {
        cout << "NO PATH FOUND!\n";
        path_t temp;
        return temp;
      }
      path.add(testmove[minpos]);
      return findpath(map,path);
    }
    Last edited by ichijoji; 09-21-2004 at 11:26 AM.
    Illusion and reality become impartiality and confidence.

  2. #2
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    I don't think the errors are in this file, it looks like it thinks several methods of your map_t class are undefined which means that file is your problem unless you just simply forgot to #include it.

    Post the code for the map_t class.

  3. #3
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179
    BEST SUGGESTION EVER.

    Dude, seriously. I went back to get the code for the map_t class and I hadn't implemented it yet. So I wrote out the three functions and it compiled fine.
    *smacks forehead*
    Illusion and reality become impartiality and confidence.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. recursive pathfinding
    By msshapira in forum C Programming
    Replies: 9
    Last Post: 02-11-2009, 03:07 PM
  2. Linker errors in VC++ 2005
    By C+/- in forum C++ Programming
    Replies: 0
    Last Post: 05-18-2007, 07:42 AM
  3. difference between recursive and iterative
    By Micko in forum C Programming
    Replies: 33
    Last Post: 07-06-2004, 09:34 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. How to change recursive loop to non recursive loop
    By ooosawaddee3 in forum C Programming
    Replies: 1
    Last Post: 06-24-2002, 08:15 AM