本文介绍了未解决的外部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个未解决的外部符号错误,这驱使我坚果。总之,我有一个包装类SDL_Surfaces('DgSurface')和一个类加载和存储DgSurfaces('DgSurfaceList')。尝试在我的项目中包括DgSurfaceList文件时,会出现链接问题。这是我的类:

I have an unresolved external symbol error that's driving me nuts. In short, I have a wrapper class for SDL_Surfaces ('DgSurface') and a class to load and store DgSurfaces ('DgSurfaceList'). The link issue arises when trying to include the DgSurfaceList files in my project. Here are my classes:

头文件DgSurface.h包含DgSurface类声明:

The header file "DgSurface.h" contains the DgSurface class declaration:

    #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.cppcontatins DgSurface定义:

The cpp file "DgSurface.cpp" contatins DgSurface definitions:

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

这个类似乎工作得很好,我开放反馈:)。

This class seems to work fine and performs as expected (however, as always, am open to feedback :).

DgSurfaceList.h包含DgSurfaceList类声明:

"DgSurfaceList.h" contains DgSurfaceList class declarations:

#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定义:

and finally "DgSurfaceList.cpp" contains DgSurfaceList definitions:

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

如果我在cpp文件中注释掉DgSurfaceList :: GetImage()定义,DgSurfaceList似乎工作正常,并存储图像正确。更具体地说,当我在上述函数中包括for循环时,链路错误才出现。

Now, if I comment out the DgSurfaceList::GetImage() definition in the cpp file, DgSurfaceList seems to work fine and store images correctly. More specifically, the link error only arises when I include the for loop in the above function. What could it be?

其他资讯:

错误:

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 ++ express 2010

Coding environment:Visual C++ express 2010

推荐答案

CrtDbgReport只有C运行时库的调试版本。所以也许你是在调试模式下编译,但链接到库的发行版本。另一种可能性是你正在以释放模式编译,但是你定义的一些宏会导致std :: list的调试版本被编译。

CrtDbgReport is defined in the debug version of the C run time library only. So perhaps you are compiling in debug mode but linking with the release version of the library. Another possibility is that you are compiling in release mode but that some macro you have defined is causing the debug version of std::list to be compiled.

这篇关于未解决的外部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-24 23:15