Herzlich Willkommen, lieber Gast!
  Sie befinden sich hier:

  Forum » C / C++ (ANSI-Standard) » Link-error bei dlls

Forum | Hilfe | Team | Links | Impressum | > Suche < | Mitglieder | Registrieren | Einloggen
  Quicklinks: MSDN-Online || STL || clib Reference Grundlagen || Literatur || E-Books || Zubehör || > F.A.Q. < || Downloads   

Autor Thread - Seiten: > 1 <
000
19.08.2005, 13:51 Uhr
DarthDevilous



In einer dll definiere ich die klasse CDataReader:


C++:
//DataReader.h

#pragma once
#include "Core.h"
#include "Object.h"
#include <list>
#include <memory>

CORE_API class CDataReader
{
public:
    CDataReader(void) { }
    virtual ~CDataReader(void) { }
    virtual std::list<Object*> LoadFile(const char *lpszFileName) = 0;
};

CORE_API class CDataReaderFactory
{
public:
    CDataReaderFactory(void);
    virtual ~CDataReaderFactory(void);
    static std::auto_ptr<CDataReader> GetReader(const char *lpszFilename) { return pFirstFactory->GetAppropriateReader(lpszFilename); }
protected:
    virtual CDataReader* AllocReader(void) = 0;
    std::auto_ptr<CDataReader> GetAppropriateReader(const char *lpszFilename);
    virtual bool CanRead(const char *lpszFilename);
private:
    CDataReaderFactory *pNextFactory;
    static CDataReaderFactory *pFirstFactory;
};

// DataReader.cpp

#include "StdAfx.h"
#include "Memory.h"
#include <memory>
#include <list>
#include "DataReader.h"

CDataReaderFactory* CDataReaderFactory::pFirstFactory = NULL;

CDataReaderFactory::CDataReaderFactory(void)
{
    Memory::RegisterPointer(this);
    pNextFactory = pFirstFactory;
    pFirstFactory = this;
}

CDataReaderFactory::~CDataReaderFactory(void)
{
    if (pFirstFactory = this)
        pFirstFactory = pNextFactory;
    else
    {
        for (CDataReaderFactory *pFactory = pFirstFactory;
            pFactory;
            pFactory = pFactory->pNextFactory)
        {
            if (pFactory->pNextFactory = this)
                pFactory->pNextFactory = pNextFactory;
        }
    }
    Memory::UnregisterPointer(this);
}

std::auto_ptr<CDataReader> CDataReaderFactory::GetAppropriateReader(const char *lpszFilename)
{
    std::auto_ptr<CDataReader> tmp;
    if (CanRead(lpszFilename))
        return std::auto_ptr<CDataReader>(AllocReader());
    else if (pNextFactory)
        return pNextFactory->GetAppropriateReader(lpszFilename);
    else
        return std::auto_ptr<CDataReader>((CDataReader*)NULL);
}

bool CDataReaderFactory::CanRead(const char *lpszFilename)
{
    return false;
}




In einer anderen dll mach ich dann eine klasse, die von CDataReader abstammt:


C++:
//ObjectReader.h

#pragma once
#include <string>
#include <list>
#include "../Core/Object.h"
#include "../Core/DataReader.h"

namespace ObjectReader
{

    class CObjectReader
    {
    public:
        CObjectReader(void);
        CObjectReader(size_t ulStartIndex);
        virtual ~CObjectReader(void);
        Object* GetObject(void) { return pThisObject; }
        std::string szName;
        std::string szInitialState;
        std::string szType;
        size_t iBeginning, iEnd;
        Object* BuildTree(void);
    protected:
        Object* pThisObject;
        std::list<CObjectReader*> lChildReaders;
        static char* pData;
        size_t ReadString(size_t ulIndex, std::string &rDest);
        size_t BuildObject(size_t ulIndex);
        size_t BuildSimpleObject(size_t ulIndex);
        void BuildSimpleNamelessObject(const char *pszString);
        size_t SkipWhite(size_t ulIndex);
        bool AnalyseFloat(double &rDest, const char *pString);
    };

    class CObjectReaderHead :
        public CObjectReader, public CDataReader
    {
    public:
        CObjectReaderHead(void);
        virtual ~CObjectReaderHead(void);
        virtual std::list<Object*> LoadFile(const char *lpszFileName);
    };

    class CObjectFileReaderFactory
        : public CDataReaderFactory
    {
    public:
        CObjectFileReaderFactory(void) { }
        virtual ~CObjectFileReaderFactory(void) { }
        bool CanRead(const char *lpszFilename) {
            if (strcmp(&lpszFilename[strlen(lpszFilename)-4], ".txt") == 0) return true;
            return false;
        }
        CDataReader* AllocReader(void) { return new CObjectReaderHead; }
    };

}

// ObjectReader.cpp

#include "StdAfx.h"
#include <fstream>
#include <list>
#include <math.h>
#include "../Core/Globals.h"
#include "../Core/Object.h"
#include "../Core/RuntimeClass.h"
#include "../Core/String.h"
#include "../Core/Float.h"
#include "../Core/Log.h"
#include "../Core/Exceptions.h"
#include "ObjectReaderExceptions.h"
#include "ObjectReader.h"


namespace ObjectReader
{
    /*
     * Die Implementierung ist recht lang, als überspringe sie jetzt. U.a. ist auch definiert:
     */

    char* CObjectReader::pData = NULL;
    CObjectFileReaderFactory thisReader;
}




Beim compilieren der ersten dll bekomme ich die verdächtig warnungen:

Code:
c:\Documents and Settings\****\My Documents\Visual Studio Projects\MetaEngine\Core\DataReader.h(13) : warning C4091: '__declspec(dllexport ) ' : ignored on left of 'CDataReader' when no variable is declared
c:\Documents and Settings\****\My Documents\Visual Studio Projects\MetaEngine\Core\DataReader.h(28) : warning C4091: '__declspec(dllexport ) ' : ignored on left of 'CDataReaderFactory' when no variable is declared



Beim compilieren der zweiten dll bekomme ich dann diese link errors:

Code:
ObjectReader.obj : error LNK2019: unresolved external symbol "public: __thiscall CDataReaderFactory::CDataReaderFactory(void)" (??0CDataReaderFactory@@QAE@XZ) referenced in function "public: __thiscall ObjectReader::CObjectFileReaderFactory::CObjectFileReaderFactory(void)" (??0CObjectFileReaderFactory@ObjectReader@@QAE@XZ)
ObjectReader.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall CDataReaderFactory::~CDataReaderFactory(void)" (??1CDataReaderFactory@@UAE@XZ) referenced in function "public: virtual __thiscall ObjectReader::CObjectFileReaderFactory::~CObjectFileReaderFactory(void)" (??1CObjectFileReaderFactory@ObjectReader@@UAE@XZ)
Debug/dObjectReader.dll : fatal error LNK1120: 2 unresolved externals



Was mach ich falsch, wie kann ich es korrigieren?


Bearbeitung von DarthDevilous:

Entschuldigung falls das in die WinAPI - abteilung gehört, ich habe hauptsächlich an einen link-problem als etwas mit den dlls gedacht. Naja - dann könnte es jemand vieleicht verschieben?


Dieser Post wurde am 19.08.2005 um 14:11 Uhr von DarthDevilous editiert.
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
Seiten: > 1 <     [ C / C++ (ANSI-Standard) ]  


ThWBoard 2.73 FloSoft-Edition
© by Paul Baecher & Felix Gonschorek (www.thwboard.de)

Anpassungen des Forums
© by Flo-Soft (www.flo-soft.de)

Sie sind Besucher: