Thread: linking error

  1. #1
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743

    linking error

    Hey guys, I'm getting a linker error in MSVC++, and it is escaping me. I can't seem to find the unresolved external symbol myself, so I thought I might post the code up here really quick and see if yall can help me find it.

    The code isn't too long, so you shouldn't worry too much. Of course linker errors are always kind of cryptic, but here is the actual error itself:

    1>animation.obj : error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: struct ANIMATION_DATA * & __thiscall std::vector<struct ANIMATION_DATA *,class std::allocator<struct ANIMATION_DATA *> >:perator[](unsigned int)" (??A?$vector@PAUANIMATION_DATA@@V?$allocator@PAUAN IMATION_DATA@@@std@@@std@@QAEAAPAUANIMATION_DATA@@ I@Z)
    So it looks like the unresolved external has something to do with my AnimationList vector inside of my ANIMATION_MANAGER. It is a vector of type ANIMATION_DATA.

    Here is the .h header file:

    Code:
    #ifndef __ANIMATION_DTP_H
    #define __ANIMATION_DTP_H
    
    #include <vector>
    
    using namespace std;
    
    #include "SDL.h"
    
    
    /**************************
    ANIMATION_DATA
    
    A structure meant for holding
    all data needed for animations
    **************************/
    
    struct ANIMATION_DATA
    {
    	SDL_Surface *surfaceData;
    	int WidthPerFrame, HeightPerFrame;
    	int FrameCount, SequenceCount;
    
    	ANIMATION_DATA ( );
    	~ANIMATION_DATA ( );
    };
    
    /***************************
    ANIMATION_MANAGER
    
    A class that manages all 
    ANIMATION_DATA structures
    ***************************/
    
    class ANIMATION_MANAGER
    {
    private:
    
    	void Copy ( const ANIMATION_MANAGER & copy );
    
    protected:
    
    	vector < ANIMATION_DATA * > AnimationList;
    
    public:
    
    	//Constructors
    	ANIMATION_MANAGER ( );
    	ANIMATION_MANAGER ( const ANIMATION_MANAGER & copy );
    	ANIMATION_MANAGER ( char *descriptorFile );
    
    	//Destructors
    	~ANIMATION_MANAGER ( );
    
    	//Accessors
    	ANIMATION_DATA *GetAnimation ( int index );
    
    	//Modifiers
    	void ClearAnimations ( );
    
    	//Actions
    	void LoadFile ( char *descriptorFile );
    
    	//Operators
    	void operator = ( const ANIMATION_MANAGER & copy );
    };
    Here is the .cpp file:

    Code:
    #include <fstream>
    #include <string>
    
    using namespace std;
    
    #include "SDL.h"
    #include "animation.h"
    #include "shared.h"
    
    /*************************
    ANIMATION_DATA structure
    *************************/
    
    ANIMATION_DATA::ANIMATION_DATA ( )
    {
    	surfaceData = NULL;
    }
    
    ANIMATION_DATA::~ANIMATION_DATA ( )
    {
    	if ( surfaceData ) SDL_FreeSurface ( surfaceData );
    }
    
    /*************************
    ANIMATION_MANAGER class
    *************************/
    
    void ANIMATION_MANAGER::Copy ( const ANIMATION_MANAGER & copy )
    {
    	AnimationList = copy.AnimationList;
    }
    
    
    //Constructors
    ANIMATION_MANAGER::ANIMATION_MANAGER ( )
    {
    	//Empty
    }
    
    ANIMATION_MANAGER::ANIMATION_MANAGER ( const ANIMATION_MANAGER & copy )
    {
    	Copy ( copy );
    }
    
    ANIMATION_MANAGER::ANIMATION_MANAGER ( char *descriptorFile )
    {
    	LoadFile ( descriptorFile );
    }
    
    //Destructors
    ANIMATION_MANAGER::~ANIMATION_MANAGER ( )
    {
    	ClearAnimations();
    }
    
    //Accessors
    ANIMATION_DATA *ANIMATION_MANAGER::GetAnimation ( int index )
    {
    	return AnimationList[index];
    }
    
    //Modifiers
    void ANIMATION_MANAGER::ClearAnimations ( )
    {
    	for ( unsigned int x = 0; x < AnimationList.size(); x++ )
    	{
    		delete AnimationList[x];
    		AnimationList[x] = NULL;
    	}
    
    	AnimationList.clear();
    }
    
    //Actions
    void ANIMATION_MANAGER::LoadFile ( char *descriptorFile )
    {
    	//The bulk of the work is done here.
    	ifstream load;
    	load.open ( descriptorFile );
    
    	string input;
    	vector < string > tokens;
    
    	ANIMATION_DATA *temp = NULL;
    
    	while ( !load.eof() )
    	{
    		//Clear the tokens vector
    		tokens.clear();
    		temp = new ANIMATION_DATA;
    
    		//Get the new input line
    		getline ( load, input );		
    		Tokenize ( input, tokens, " " );
    
    		if ( tokens.size() < 5 ) return;
    
    		//Process the animation data
    		temp->surfaceData = SDL_LoadBMP ( tokens[0].c_str() );
    
    		SDL_SetColorKey ( temp->surfaceData, SDL_SRCCOLORKEY | SDL_RLEACCEL , 
    			SDL_MapRGB(temp->surfaceData->format, 255, 0, 255) );
    
    		temp->HeightPerFrame = atoi ( tokens[1].c_str() );
    		temp->WidthPerFrame = atoi ( tokens[2].c_str() );
    		temp->FrameCount = atoi ( tokens[3].c_str() );
    		temp->SequenceCount = atoi ( tokens[4].c_str() );
    
    		//Push the new animation onto the animation list
    		AnimationList.push_back ( temp );
    
    		//NULL out the pointer to the animation data.
    		temp = NULL;
    	}
    
    	return;
    }
    
    //Operators
    void ANIMATION_MANAGER::operator = ( const ANIMATION_MANAGER & copy )
    {
    	Copy ( copy );
    }
    Anyways, hopefully we can find this linking error. Thanks for any help.
    My Website

    "Circular logic is good because it is."

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    This probably is related to your issue:

    http://forums.microsoft.com/MSDN/Sho...26137&SiteID=1

  3. #3
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    hmm...i guess it could be that...although I must say it would seem kind of strange because it is not the first time I have compiled and linked this project. I have done it successfully before, so for it to be an error like you suggest would be kind of strange. I will try working with that though. It would make more sense to me, however, if it was an error with this code...since it is the recently added code to the project.
    My Website

    "Circular logic is good because it is."

  4. #4
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    Well after hours of trying to find the error...I finally isolated it down to the small function of push_back from the vector class. Whenever I commented that line out, it worked great. Whenever I didn't, it gave me a linking error. Not sure why.

    So I decided to set up an SDL project in Code::Blocks, and I copied all my code over exactly (just moved the files over, and then included them in the project). Compiled and ran great. Not a single problem.

    Strange.
    My Website

    "Circular logic is good because it is."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM