2012-08-12 14 views
7

Ich habe einen ungelösten externen Symbolfehler, der mich verrückt macht. Kurz gesagt, ich habe eine Wrapper-Klasse für SDL_Surfaces ('DgSurface') und eine Klasse zum Laden und Speichern von DgSurfaces ('DgSurfaceList'). Das Verbindungsproblem tritt auf, wenn Sie versuchen, die DgSurfaceList-Dateien in meinem Projekt einzubeziehen. Hier sind meine Klassen:ungelöst extern

Die Header-Datei "DgSurface.h" enthält die DgSurface Klassendeklaration:

#ifndef DGSURFACE_H 
    #define DGSURFACE_H 

    #include "SDL.h" 
    #include <string> 

    class DgSurface 
    { 
    public: 

     //Constructor/destructor 
     DgSurface(std::string N, SDL_Surface* I): image(I), name(N) {} 
     DgSurface() {name = ""; image = NULL;} 
     ~DgSurface(); 

     //Copy operations 
     DgSurface(const DgSurface&); 
     DgSurface& operator= (const DgSurface&); 

     //Data members 
     std::string name;  //The name of the image 
     SDL_Surface* image;  //The image 
    }; 

    #endif 

Die CPP-Datei "DgSurface.cpp" contatins DgSurface Definitionen:

#include "DgSurface.h" 
#include "SDL.h" 

//-------------------------------------------------------------------------------- 
//  Constructor 
//-------------------------------------------------------------------------------- 
DgSurface::DgSurface(const DgSurface& other) 
{ 
    //Copy name 
    name = other.name; 

    //Create new SDL_Surface 
    image = SDL_ConvertSurface(other.image, other.image->format, 0); 
} 


//-------------------------------------------------------------------------------- 
//  Destructor 
//-------------------------------------------------------------------------------- 
DgSurface::~DgSurface() 
{ 
    SDL_FreeSurface(image); 
} 


//-------------------------------------------------------------------------------- 
//  Assignment operator 
//-------------------------------------------------------------------------------- 
DgSurface& DgSurface::operator= (const DgSurface& other) 
{ 
    // if same object 
    if (this == &other) 
     return *this; 

    //Copy name 
    name = other.name; 

    //Create new SDL_Surface 
    image = SDL_ConvertSurface(other.image, other.image->format, 0); 

    return *this; 
} 

Diese Klasse scheint gut zu funktionieren und funktioniert wie erwartet (bin aber wie immer offen für Feedback :).

"DgSurfaceList.h" enthält DgSurfaceList Klassendeklarationen:

#ifndef DGSURFACELIST_H 
#define DGSURFACELIST_H 

#include "SDL.h" 
#include <list> 
#include <string> 
#include "DgSurface.h" 


class DgSurfaceList 
{ 
    public: 
     //Constructors/destructor 
     DgSurfaceList() {} 
     ~DgSurfaceList() {} 

     //Functions 
     bool AddImage(std::string location, std::string name); 

     //Return Functions 
     SDL_Surface* GetImage(std::string S) const; 

    private: 
     //Data members 
     std::list<DgSurface> imlist; //The list of DgSurfaces 

     //Functions 
     SDL_Surface* LoadImage(std::string filename); 
}; 


#endif 

und schließlich "DgSurfaceList.cpp" enthält DgSurfaceList Definitionen:

#include "SDL.h" 
#include "SDL_image.h" 
#include <list> 
#include <string> 
#include "DgSurface.h" 
#include "DgSurfaceList.h" 


//-------------------------------------------------------------------------------- 
//  Load an image from file 
//-------------------------------------------------------------------------------- 
SDL_Surface* DgSurfaceList::LoadImage(std::string filename) 
{ 
    //Loads an image from file, returns SDL_surface* 
    ... 

} //End:DgSurfaceList::LoadImage() 


//-------------------------------------------------------------------------------- 
//  Add a DgSurface to the list 
//-------------------------------------------------------------------------------- 
bool DgSurfaceList::AddImage(std::string location, std::string name) 
{ 
    //Load the image 
    DgSurface temp(name,LoadImage(location)); 

    //If there was an error in loading the image 
    if(temp.image == NULL) 
     return false; 

    //If everything loaded fine, place a copy into imlist 
    imlist.push_back(temp); 

    return true; 

} //End: DgSurfaceList::AddImage(); 


//-------------------------------------------------------------------------------- 
//  Searches imlist for an image, returns a pointer to a SDL_Surface 
//-------------------------------------------------------------------------------- 
SDL_Surface* DgSurfaceList::GetImage(std::string S) const 
{ 
    std::list<DgSurface>::const_iterator i; 

    //Search imlist for DgSurface of the same name 
    for (i = imlist.begin(); i != imlist.end(); i++) 
    { 
     if (S.compare((*i).name) == 0) 
      return (*i).image; 
    } 

    //Return Null if name not found 
    return NULL; 

} //End:DgSurfaceList::GetImage() 

Nun, wenn ich den DgSurfaceList Kommentar out :: GetImage() Definition in der cpp-Datei, DgSurfaceList scheint gut zu funktionieren und Bilder korrekt zu speichern. Genauer gesagt tritt der Verbindungsfehler nur auf, wenn ich die for-Schleife in die obige Funktion einfüge. Was könnte es sein?

Weitere Informationen:

Fehler:

unresolved external symbol __imp___CrtDbgReportW referenced in function "public: class 
DgSurface const & __thiscall std::_List_const_iterator<class std::_List_val<class 
DgSurface,class std::allocator<class DgSurface> > >::operator*(void)const " 

Coding Umgebung: nur Visual C 2010

Antwort

11

CrtDbgReport express ++ ist in der Debug-Version der C-Laufzeitbibliothek definiert. Vielleicht kompilieren Sie also im Debug-Modus, verlinken aber mit der Release-Version der Library. Eine weitere Möglichkeit ist, dass Sie im Freigabemodus kompilieren, aber dass ein Makro, das Sie definiert haben, die Debug-Version von std :: list kompiliert.

+3

Danke, ich habe Eigenschaften-> C/C++ -> Codegenerierung-> Laufzeitbibliothek auf Mt Debug DLL eingestellt und kann jetzt kompilieren. Ich bin mir nicht sicher, warum das so ist, aber ich werde darüber nachdenken. – Frank

+2

Ich hatte dieses Problem auch mit Boost und opencv zusammen. Es gibt mögliche Erklärungen zu den _DEBUG oder NDEBUG Flags, in meinem Fall haben sie keinen Einfluss auf dieses Problem. Danke euch beiden. –

+1

Das Ändern von _DEBUG zu NDEBUG löste unsere jüngsten Kopfschmerzen. Vielen Dank! – Jon