delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/20/08:30:31

From: "Gringo" <jackgibs AT sprynet DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Why 'undefined reference' in link?
Date: 19 Apr 1997 21:56:24 GMT
Organization: InterServ News Service
Lines: 156
Message-ID: <01bc4d0c$7b280d60$c6ceaec7@gibsonjb>
NNTP-Posting-Host: dd64-198.compuserve.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I am new to DJGPP.  I have a problem and would appreciate any help.  It's
probably something simple I am overlooking.

When using RHIDE 1.2, and trying to Make using the following files in
a project, I get the following error messages during link:

Creating: hexgrid.exe
Error: hex.o: In function `HEX::SetSize(int)':
hex.cc(15) Error: undefined reference to `HEX::size'
Error: hex.o: In function `HEX::GetSize(void)':
hex.cc(20) Error: undefined reference to `HEX::size'
Error: hex.o: In function `HEX::SetOffset(XY, int)':
hex.cc(25) Error: undefined reference to `HEX::offset'
Error: hex.cc(.text+0x27a): undefined reference to `HEX::offset'
Error: hex.o: In function `HEX::GetOffset(int)':
hex.cc(30) Error: undefined reference to `HEX::offset'
Error: hex.cc(.text+0x2a5): undefined reference to `HEX::offset'
Error: hex.o: In function `HEX::InitHex(int)':
hex.cc(39) Error: undefined reference to `HEX::size'
hex.cc(41) Error: undefined reference to `HEX::offset'
Error: hex.cc(.text+0x33b): undefined reference to `HEX::offset'
hex.cc(42) Error: undefined reference to `HEX::offset'
Error: hex.cc(.text+0x35e): undefined reference to `HEX::offset'
Error: hex.cc(.text+0x385): undefined reference to `HEX::offset'
Error: hex.o(.text+0x38e):hex.cc: more undefined references to
`HEX::offset'
There were some errors

I tried compiling and linking the same files using Turbo C++ and there were
no errors.

/***********   hex.h   *************/

#ifndef __HEX_H
#define __HEX_H

#include "xy.h"

class HEX {
private:
   static int size;
   static XY offset[6];
public:
   static void SetSize(int);
   static int GetSize();
   static void SetOffset(XY, int);
   static XY GetOffset(int);
   static void InitHex(int);
private:
   XY center;
   XY vert[6];
   XY area[3][4];
   XY location;
public:
   HEX();
   HEX(XY loc);
   ~HEX();
public:
   void SetCenter(XY c);
   void SetLocation(const XY l) { location = l; }
   const XY GetLocation() { return location; }
   int IsIn(XY n);
};

#endif

/***********   End hex.h   *************/

/***********   hex.cc   *************/

#include <allegro.h>
#include "hex.h"
#include "xy.h"

HEX::HEX() { }

HEX::HEX(XY loc) { location = loc; }

HEX::~HEX() { }

void HEX::SetSize(int s)
{
   size = s;
}

int HEX::GetSize()
{
   return size;
}

void HEX::SetOffset(XY o, int i)
{
   offset[i] = o;
}

XY HEX::GetOffset(int i)
{
   return offset[i];
}

void HEX::InitHex(int s)
{
   int A = s;
   int B = 2 * A / 3;
   int C = A / 3;

   size = s;

   offset[0] = XY(A / 2, A / 2 + C);
   offset[1] = XY(offset[0].x() + A, offset[0].y());
   offset[2] = XY(offset[1].x() + C, offset[1].y() + B);
   offset[3] = XY(offset[2].x() - C, offset[2].y() + B);
   offset[4] = XY(offset[3].x() - A, offset[3].y());
   offset[5] = XY(offset[4].x() - C, offset[4].y() - B);
}

void HEX::SetCenter(XY c)
{
   center = c;

   for(int i=0; i<6; i++)
      vert[i] = HEX::offset[i] + c;

   int dat[12] = { 0, 1, 3, 4, 1, 2, 4, 5, 2, 3, 5, 0 };
   for(int a=0; a<3; a++) {
      for(int b=0; b<4; b++) {
         area[a][b] = vert[dat[a*4+b]];
      }
   }
}

int HEX::IsIn(XY n)
{

}

/***********   End hex.cc   *************/

/***********   hexmain.cc   *************/

#include "hex.h"

int main(void)
{
   HEX h;

   h.SetSize(5);

   return 0;
}

/***********   End hexmain.cc   *************/




- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019