Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Need help with linker errors (C++)  (Read 1965 times)

0 Members and 1 Guest are viewing this topic.
Need help with linker errors (C++)
« on: December 12, 2008, 12:52:26 am »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
Can someone look at this and help me figure out how to fix these linker errors?

Code: [Select]
HMD.h

#ifndef _HMD_H_
#define _HMD_H_

#include "entInfo.h"
#define _HMDID 1001030205 //ID for this file type

class CBaseHMD
{
public:
CBaseHMD(){};
int HMDID;
std::string mapName;
int spriteCount;
HVSTDAT<unsigned char *> spriteBase(); //all the sprites in this thing
int soundCount;
HVSTDAT<CBaseSound> soundBase(); //all the sounds in this thing
int entCount;
HVSTDAT<CBaseEntInfo> entities(); //all the entities in this thing
};

namespace HMDFunc
{
CBaseHMD readMap(const char * fileName);
};

Code: [Select]
HMD.cpp

#include "HMD.h"
#include "stdio.h"
#include "stdlib.h"

CBaseHMD HMDFunc::readMap(const char * fileName)
{
CBaseHMD temp;
FILE *mapFile;
unsigned char * tempSprite;

mapFile = fopen(fileName, "rb");

if (mapFile == NULL)
return temp;

fread(&temp.HMDID, sizeof(temp.HMDID), 1, mapFile);

if (temp.HMDID != _HMDID)
return temp;

fread(&temp.mapName, sizeof(temp.mapName), 1, mapFile);
fread(&temp.spriteCount, sizeof(temp.spriteCount), 1, mapFile);

for (int i = 0; i < temp.spriteCount; i++)
{
fread(&tempSprite, sizeof(tempSprite), 1, mapFile);
temp.spriteBase().addData(tempSprite);
}



return temp;
}

the errors read:
Quote
HMD.obj : error LNK2001: unresolved external symbol "public: __thiscall HVSTDAT<unsigned char *>::~HVSTDAT<unsigned char *>(void)" (??1?$HVSTDAT@PAE@@QAE@XZ)
1>HMD.obj : error LNK2001: unresolved external symbol "public: void __thiscall HVSTDAT<unsigned char *>::addData(unsigned char *)" (?addData@?$HVSTDAT@PAE@@QAEXPAE@Z)
1>HMD.obj : error LNK2001: unresolved external symbol "public: class HVSTDAT<unsigned char *> __thiscall CBaseHMD::spriteBase(void)" (?spriteBase@CBaseHMD@@QAE?AV?$HVSTDAT@PAE@@XZ)
1>C:\Harvest Engine\src\HVSTCORE\Debug\HVSTCORE.exe : fatal error LNK1120: 3 unresolved externals
I'm never good with linker errors -.-  If anyone needs to see the definition of the HVSTDAT class, give me a shout.
Logged



i love big weenies and i cannot lie
Re: Need help with linker errors (C++)
« Reply #1 on: December 12, 2008, 08:12:05 am »
  • (y)(;>.<;)(y)
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3293
   HVSTDAT<unsigned char *> spriteBase(); //all the sprites in this thing
   HVSTDAT<CBaseSound> soundBase(); //all the sounds in this thing
   HVSTDAT<CBaseEntInfo> entities(); //all the entities in this thing

These are red-herrings. Look closely, you are actually declaring functions which return an object of HVSTDAT.
« Last Edit: December 12, 2008, 08:13:45 am by TheDarkJay »
Logged
Re: Need help with linker errors (C++)
« Reply #2 on: December 12, 2008, 09:09:54 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 2245
yeah, HVSTDAT needs to be defined before CBaseHMD.  or perhaps yours attemptings to use them functions and u haven't delcared thesm
Logged
Re: Need help with linker errors (C++)
« Reply #3 on: December 12, 2008, 09:34:12 am »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
   HVSTDAT<unsigned char *> spriteBase(); //all the sprites in this thing
   HVSTDAT<CBaseSound> soundBase(); //all the sounds in this thing
   HVSTDAT<CBaseEntInfo> entities(); //all the entities in this thing

These are red-herrings. Look closely, you are actually declaring functions which return an object of HVSTDAT.
This.
Logged
Re: Need help with linker errors (C++)
« Reply #4 on: December 13, 2008, 06:45:02 pm »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
What I was trying to do was declare them as a part of the class..without the () it threw a bunch of errors at me.  So I stuck the () on them and it seemed happy with it =\  Lemme try this again..
Logged



i love big weenies and i cannot lie
Re: Need help with linker errors (C++)
« Reply #5 on: December 13, 2008, 07:15:53 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
What I was trying to do was declare them as a part of the class..without the () it threw a bunch of errors at me.  So I stuck the () on them and it seemed happy with it =\  Lemme try this again..
lol, not a good move. Just sticking random characters onto declarations may make the compiler happy, but it sure won't produce the output you want.
Logged
Re: Need help with linker errors (C++)
« Reply #6 on: December 13, 2008, 07:53:56 pm »
  • The devil in the mirror.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 238
What I was trying to do was declare them as a part of the class..without the () it threw a bunch of errors at me.  So I stuck the () on them and it seemed happy with it =\  Lemme try this again..

What kind of errors do you get without them?
Or does it all work now? :P
Logged
Working on my Masters Degree in Computer Science.
Hey look, Zelda Coop....later.
Proud user of C++ for 9 years, and counting!
Re: Need help with linker errors (C++)
« Reply #7 on: December 14, 2008, 01:58:27 am »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
What I was trying to do was declare them as a part of the class..without the () it threw a bunch of errors at me.  So I stuck the () on them and it seemed happy with it =\  Lemme try this again..
lol, not a good move. Just sticking random characters onto declarations may make the compiler happy, but it sure won't produce the output you want.

Haha, I noticed.  It made sense to me at the time, but now that I'm thinking about it...what I did made NO sense at all lmao.

Hang on, while I pull those other errors up..

EDIT: haha..cool..

Code: [Select]
#include "HMD.h"
#include "stdio.h"
#include "stdlib.h"

CBaseHMD HMDFunc::readMap(const char * fileName)
{
CBaseHMD temp;
FILE *mapFile;
unsigned char * tempSprite;

mapFile = fopen(fileName, "rb");

if (mapFile == NULL)
return temp;

fread(&temp.HMDID, sizeof(temp.HMDID), 1, mapFile);

if (temp.HMDID != _HMDID)
return temp;

fread(&temp.mapName, sizeof(temp.mapName), 1, mapFile);
fread(&temp.spriteCount, sizeof(temp.spriteCount), 1, mapFile);

for (int i = 0; i < temp.spriteCount; i++)
{
fread(&tempSprite, sizeof(tempSprite), 1, mapFile);
temp.spriteBase.addData(tempSprite);
}




return temp;
}

and the errors:
Quote
>HMD.obj : error LNK2019: unresolved external symbol "public: void __thiscall HVSTDAT<unsigned char *>::addData(unsigned char *)" (?addData@?$HVSTDAT@PAE@@QAEXPAE@Z) referenced in function "class CBaseHMD __cdecl HMDFunc::readMap(char const *)" (?readMap@HMDFunc@@YA?AVCBaseHMD@@PBD@Z)

1>HMD.obj : error LNK2019: unresolved external symbol "public: __thiscall HVSTDAT<class CBaseSound>::~HVSTDAT<class CBaseSound>(void)" (??1?$HVSTDAT@VCBaseSound@@@@QAE@XZ) referenced in function __unwindfunclet$??0CBaseHMD@@QAE@XZ$0

1>HMD.obj : error LNK2019: unresolved external symbol "public: __thiscall HVSTDAT<unsigned char *>::~HVSTDAT<unsigned char *>(void)" (??1?$HVSTDAT@PAE@@QAE@XZ) referenced in function __unwindfunclet$??0CBaseHMD@@QAE@XZ$0

1>HMD.obj : error LNK2019: unresolved external symbol "public: __thiscall HVSTDAT<struct CBaseEntInfo>::HVSTDAT<struct CBaseEntInfo>(void)" (??0?$HVSTDAT@UCBaseEntInfo@@@@QAE@XZ) referenced in function "public: __thiscall CBaseHMD::CBaseHMD(void)" (??0CBaseHMD@@QAE@XZ)

1>HMD.obj : error LNK2019: unresolved external symbol "public: __thiscall HVSTDAT<class CBaseSound>::HVSTDAT<class CBaseSound>(void)" (??0?$HVSTDAT@VCBaseSound@@@@QAE@XZ) referenced in function "public: __thiscall CBaseHMD::CBaseHMD(void)" (??0CBaseHMD@@QAE@XZ)

1>HMD.obj : error LNK2019: unresolved external symbol "public: __thiscall HVSTDAT<unsigned char *>::HVSTDAT<unsigned char *>(void)" (??0?$HVSTDAT@PAE@@QAE@XZ) referenced in function "public: __thiscall CBaseHMD::CBaseHMD(void)" (??0CBaseHMD@@QAE@XZ)

1>HMD.obj : error LNK2019: unresolved external symbol "public: __thiscall HVSTDAT<struct CBaseEntInfo>::~HVSTDAT<struct CBaseEntInfo>(void)" (??1?$HVSTDAT@UCBaseEntInfo@@@@QAE@XZ) referenced in function "public: __thiscall CBaseHMD::~CBaseHMD(void)" (??1CBaseHMD@@QAE@XZ)

1>C:\Harvest Engine\src\HVSTCORE\Debug\HVSTCORE.exe : fatal error LNK1120: 7 unresolved externals
« Last Edit: December 14, 2008, 02:04:30 am by MG-Zero »
Logged



i love big weenies and i cannot lie
Re: Need help with linker errors (C++)
« Reply #8 on: December 14, 2008, 02:10:19 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 2245
Assuming that you have your class defined in the header, and you have your functions for that class defined in a separate cpp file.  With templates, everything must be defined in the class itself, you can't separate them.
Logged
Re: Need help with linker errors (C++)
« Reply #9 on: December 14, 2008, 02:12:59 am »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
Oh, wow, news to me.  That would explain a lot.  Can I use a .hpp file by any chance?
Logged



i love big weenies and i cannot lie
Re: Need help with linker errors (C++)
« Reply #10 on: December 14, 2008, 11:40:44 am »
  • (y)(;>.<;)(y)
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3293
I think most (if not all) compilers treat .hpp and .h files as the same.

From what I can tell .hpp was supposed to be a C++ Header File in the same way a .h is a C Header File, but many programmers were just too lazy to change their ways xD

P.s Don't quote me on this, I may be horrendously wrong...
« Last Edit: December 14, 2008, 11:45:15 am by TheDarkJay »
Logged
Re: Need help with linker errors (C++)
« Reply #11 on: December 15, 2008, 02:40:53 am »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
yep, worked perfectly.  Thanks, guys  :)
Logged



i love big weenies and i cannot lie
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.283 seconds with 59 queries.

anything