2012-08-12 27 views
7

私には未解決の外部シンボルエラーがあり、それが私を苦労させています。要するに、SDL_Surfaces( 'DgSurface')用のラッパークラスとDgSurfaces( 'DgSurfaceList')をロードして格納するクラスがあります。プロジェクトにDgSurfaceListファイルを含めるときにリンクの問題が発生します。ここに私のクラスは次のとおりです。未解決の外部

#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 

CPPファイル "DgSurface.cpp" contatins DgSurface定義:

#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; 
} 

ヘッダファイル "DgSurface.hは" DgSurfaceクラスの宣言が含まれています

このクラスはうまく動作しているように見えますが、いつものように、フィードバックとして公開されています。

"DgSurfaceList.hは" DgSurfaceListクラスの宣言が含まれています

#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 

、最後に "DgSurfaceList.cppは" DgSurfaceListの定義が含まれています。今

#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() 

、私はDgSurfaceList ::のgetImageをコメントアウトした場合()定義をcppファイルに入れると、DgSurfaceListは正常に動作し、画像を正しく保存するようです。より具体的には、リンクエラーは、上記の関数にforループを含めると発生します。どうなり得るか?

その他の情報:

エラー:

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 " 

コーディング環境: のVisual C 2010

答えて

11

CrtDbgReportを表現++にのみCランタイムライブラリのデバッグバージョンで定義されています。したがって、おそらくあなたはデバッグモードでコンパイルしていますが、ライブラリのリリースバージョンとリンクしています。もう一つの可能​​性は、リリースモードでコンパイルしているが、定義したマクロによっては、std :: listのデバッグバージョンがコンパイルされているということです。

+3

ありがとうございます。プロパティ - > C/C++ - >コード生成 - >ランタイムライブラリをMtデバッグDLLに設定してコンパイルできるようになりました。私はこれがなぜそうであるのか不明ですが、それを調べます。 – Frank

+2

私はまた、boostとopencvを一緒に使ってこの問題を抱えていました。 _DEBUGまたはNDEBUGフラグに関する説明がありますが、私の場合はこの問題に影響しません。 ありがとうございます。 –

+1

_DEBUGをNDEBUGに変更すると、最近の頭痛が解決されました。ありがとう! – Jon