[C/C++] LNK2019 - Verweis auf nicht aufgelöstes externes Symbol

Dieses Thema im Forum "Programmierung & Entwicklung" wurde erstellt von Characticl D, 8. April 2011 .

Status des Themas:
Es sind keine weiteren Antworten möglich.
  1. 8. April 2011
    LNK2019 - Verweis auf nicht aufgelöstes externes Symbol

    Hey Leute, habe ein Problem ich schreibe gerade an einer Schnittstelle für einen Kartenleser. Bin in den ersten Zeilen und kriege immer den blöden Linker-Error, wäre cool, wenn jemand wüsste worand das liegt :/

    Die erste Zeile in der main-Funktion habe ich aus der .h gezogen, keine Ahnung obs stimmt. Der Rest ist aus dem Developers Guide.

    Fehlermeldungen:
    Code:
    eID.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""__declspec(dllimport) public: static void __cdecl eIDMW::BEID_ReaderSet::releaseSDK(void)" (__imp_?releaseSDK@BEID_ReaderSet@eIDMW@@SAXXZ)" in Funktion "_main".
    eID.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""__declspec(dllimport) public: static void __cdecl eIDMW::BEID_ReaderSet::initSDK(bool)" (__imp_?initSDK@BEID_ReaderSet@eIDMW@@SAX_N@Z)" in Funktion "_main".
    eID.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""__declspec(dllimport) public: static class eIDMW::BEID_ReaderSet & __cdecl eIDMW::BEID_ReaderSet::instance(void)" (__imp_?instance@BEID_ReaderSet@eIDMW@@SAAAV12@XZ)" in Funktion "_main".
    D:\Projekte\eID\Debug\eID.exe : fatal error LNK1120: 3 nicht aufgelöste externe Verweise.
    main.cpp
    Code:
    #include "C:\include\eidlib.h"
    
    using namespace eIDMW;
    
    void main( int argc, char* argv[])
    {
     BEID_ReaderSet::instance();
     
     BEID_ReaderSet::initSDK();
     // access the eID card here
     // ...
    
     BEID_ReaderSet::releaseSDK();
     
    }
    Auszug aus eidlib.h
    Code:
    /* ****************************************************************************
     * eID Middleware Project.
     * Copyright (C) 2008-2009 FedICT.
     *
     * This is free software; you can redistribute it and/or modify it
     * under the terms of the GNU Lesser General Public License version
     * 3.0 as published by the Free Software Foundation.
     *
     * This software is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
     * Lesser General Public License for more details.
     *
     * You should have received a copy of the GNU Lesser General Public
     * License along with this software; if not, see
     * http://www.gnu.org/licenses/.
    **************************************************************************** */
    
    #pragma once
    
    #ifndef __BEIDLIB_H__
    #define __BEIDLIB_H__
    
    #include <string>
    #include <vector>
    #include <map>
    #include "eidlibdefines.h"
    
    namespace eIDMW
    {
    
    struct SDK_Context;
    
    class CMutex;
    class BEID_Exception;
    
    /******************************************************************************//**
     * Base class for the object of BEID SDK (Can not be instantiated).
     *********************************************************************************/
    class BEID_Object
    {
    public:
     BEIDSDK_API virtual ~BEID_Object()=0; /**< Destructor */
    
    
     NOEXPORT_BEIDSDK void Init(const SDK_Context *context,void *impl); /**< For internal use : Initialize pimpl */
    
     /**
     * Release the objects instantiated within this BEID_Object.
     * Automatically call in the destructor.
     */
     NOEXPORT_BEIDSDK void Release();
    
    protected:
     BEID_Object(const SDK_Context *context,void *impl); /**< For internal use : Constructor */
     void addObject(BEID_Object *impl); /**< For internal use : Add linked object */
     void backupObject(unsigned long idx); /**< For internal use : Backup linked object */
     BEID_Object *getObject(unsigned long idx); /**< For internal use : Return an object by its index */
     BEID_Object *getObject(void *impl); /**< For internal use : Return an object by its impl */
     void delObject(unsigned long idx); /**< For internal use : Delete an object by its index */
     void delObject(void *impl); /**< For internal use : Delete an object by its impl */
    
     void checkContextStillOk() const; /**< For internal use : check if the Context is still correct (the card hasn't changed) */
    
     BEID_Object(const BEID_Object& obj); /**< Copy not allowed - not implemented */
     BEID_Object& operator= (const BEID_Object& obj); /**< Copy not allowed - not implemented */
    
     bool m_delimpl; /**< For internal use : m_impl object must be deleted */
     void *m_impl; /**< For internal use : pimpl pointer */
     unsigned long m_ulIndexExtAdd; /**< For internal use : extended add object */
     std::map<unsigned long,BEID_Object *> m_objects; /**< For internal use : Map of object instantiated within this BEID_Object */
    
     SDK_Context *m_context; /**< For internal use : context structure */
    
     //CMutex *m_mutex;
    };
    
    class BEID_Card;
    
    class CByteArray;
    
    /******************************************************************************//**
     * This class is used to receive/pass bytes array from/to different method in the SDK.
     *********************************************************************************/
    class BEID_ByteArray : public BEID_Object
    {
    public:
     BEIDSDK_API BEID_ByteArray(); /**< Default constructor */
     BEIDSDK_API BEID_ByteArray(const BEID_ByteArray &bytearray); /**< Copy constructor */
    
     /**
     * Constructor - initialize a byte array with an array of unsigned char.
     *
     * @param pucData is the byte array
     * @param ulSize is the size of the array
     */
     BEIDSDK_API BEID_ByteArray(const unsigned char * pucData, unsigned long ulSize);
    
     BEIDSDK_API virtual ~BEID_ByteArray(); /**< Destructor */
    
     /**
     * Append data to the byte array.
     *
     * @param pucData is the byte array
     * @param ulSize is the size of the array
     */
     BEIDSDK_API void Append(const unsigned char * pucData, unsigned long ulSize);
    
     /**
     * Append data to the byte array.
     */
     BEIDSDK_API void Append(const BEID_ByteArray &data);
    
     /**
     * Remove the data from the byte array.
     */
     BEIDSDK_API void Clear();
    
     /**
     * Return true if the content of data is the same as this.
     */
     BEIDSDK_API bool Equals(const BEID_ByteArray &data) const;
    
     /**
     * Return the number of bytes in the array.
     */
     BEIDSDK_API unsigned long Size() const;
    
     /**
     * Return the array of bytes in the object.
     * If Size() == 0, then NULL is returned.
     */
     BEIDSDK_API const unsigned char *GetBytes() const;
    
     /**
     * Writing the binary content to a file.
     */
     BEIDSDK_API bool writeToFile(const char * csFilePath);
    
     /**
     * Copy content of bytearray.
     */
     BEIDSDK_API BEID_ByteArray &operator=(const BEID_ByteArray &bytearray);
    
     NOEXPORT_BEIDSDK BEID_ByteArray(const SDK_Context *context,const CByteArray &impl); /**< For internal use : construct from lower level object*/
     NOEXPORT_BEIDSDK BEID_ByteArray &operator=(const CByteArray &bytearray); /**< For internal use : copy from lower level object*/
    };
    
    /******************************************************************************//**
     * These structure are used for compatibility with old C sdk.
     *********************************************************************************/
    struct BEID_RawData_Eid
    {
     BEID_ByteArray idData;
     BEID_ByteArray idSigData;
     BEID_ByteArray addrData;
     BEID_ByteArray addrSigData;
     BEID_ByteArray pictureData;
     BEID_ByteArray cardData;
     BEID_ByteArray tokenInfo;
     BEID_ByteArray certRN;
     BEID_ByteArray challenge;
     BEID_ByteArray response;
    };
    
    struct BEID_RawData_Sis
    {
     BEID_ByteArray idData;
    };
    
    /**
     * This define give an easy access to singleton (no declaration/instantiation is needed).
     *
     * Usage : ReaderSet.SomeMethod().
     */
    #define ReaderSet BEID_ReaderSet::instance()
    
    /**
     * Init the SDK (Optional).
     */
    #define BEID_InitSDK() BEID_ReaderSet::initSDK()
    
    /**
     * Release the SDK.
     * THIS MUST BE CALLED WHEN THE SDK IS NOT NEEDED ANYMORE AND BEFORE THE APPLICATION IS CALLED.
     * IF NOT RELEASE PROPERLY, AN EXCEPTION BEID_ExReleaseNeeded IS THROWN.
     */
    #define BEID_ReleaseSDK() BEID_ReaderSet::releaseSDK()
    
    class BEID_ReaderContext;
    class APL_ReaderContext;
    
    /******************************************************************************//**
     * This is a singleton class that is the starting point to get all other objects.
     * You get an instance from the static instance() method (or using the define ReaderSet).
     * Then you get a READER (BEID_ReaderContext)
     * -> from this reader, you a CARD (BEID_Card or derived class)
     * -> from this card, you get DOCUMENT (BEID_XMLDoc or derived class)
     * -> ...
     *********************************************************************************/
    class BEID_ReaderSet : public BEID_Object
    {
    public:
     BEIDSDK_API static BEID_ReaderSet &instance(); /**< Return the singleton object (create it at first use) */
    
     /**
     * Init the SDK (Optional).
     * @param bManageTestCard If true the applayer must ask if test cards are allowed (used for compatibility with old C API).
     * @param bManageTestCard If false other applications (ex. gui) take that into their scope
     */
     BEIDSDK_API static void initSDK(bool bManageTestCard=false);
     BEIDSDK_API static void releaseSDK(); /**< Release the SDK */
    
     BEIDSDK_API virtual ~BEID_ReaderSet(); /**< Destructor */
    
     /**
     * Release the readers (Useful if readers had changed).
     *
     * @param bAllReference If true all the invalid reference/pointer are destroyed.
     * @param bAllReference PUT THIS PARAMETER TO TRUE IS THREAD UNSAFE.
     * @param bAllReference You have to be sure that you will not use any old reference/pointer after this release
     */
     BEIDSDK_API void releaseReaders(bool bAllReference=false);
    
     /**
     * Return true if readers has been added or removed
     */
     BEIDSDK_API bool isReadersChanged() const;
    
     /**
     * Get the list of the reader.
     * Return an array of const char *
     * The last pointer is NULL
     * Usage : const char * const *ppList=BEID_ReaderSet::readerList();
     * for(const char * const *ppName=ppList;*ppName!=NULL;ppName++) {...}
     *
     * @param bForceRefresh force the reconnection to the lower layer to see if reader list have changed
     */
     BEIDSDK_API const char * const *readerList(bool bForceRefresh=false);
    
     /**
     * Return the first readercontext with a card.
     * If no card is present, return the firs reader.
     * If no reader exist, throw an exception BEID_ExNoReader.
     */
     BEIDSDK_API BEID_ReaderContext &getReader();
    
     /**
     * Get the reader by its name.
     */
     BEIDSDK_API BEID_ReaderContext &getReaderByName(const char *readerName);
    
     /**
     * Return the number of card readers connected to the computer.
     *
     * @param bForceRefresh force the reconnection to the lower layer to see if reader list have changed
     */
     BEIDSDK_API unsigned long readerCount(bool bForceRefresh=false);
    
     /**
     * Get the name of the reader by its Index.
     * Throw BEID_ExParamRange exception if the index is out of range.
     */
     BEIDSDK_API const char *getReaderName(unsigned long ulIndex);
    
     /**
     * Get the reader by its Index.
     * Throw BEID_ExParamRange exception if the index is out of range.
     */
     BEIDSDK_API BEID_ReaderContext &getReaderByNum(unsigned long ulIndex);
    
     /**
     * Return the reader containing the card with this SN.
     * If no card with this SN is found, throw an exception BEID_ExParamRange.
     */
     BEIDSDK_API BEID_ReaderContext &getReaderByCardSerialNumber(const char *cardSerialNumber);
    
     /**
     * Flush the cached files.
     * Return if any files were flushed (T/F).
     */;
     BEIDSDK_API bool flushCache(); /**< Flush the cache */
    
     NOEXPORT_BEIDSDK BEID_ReaderContext &getReader(APL_ReaderContext *pAplReader); /**< For internal use - Not exported*/
    
    private:
     BEID_ReaderSet(); /**< For internal use : Constructor */
    
     BEID_ReaderSet(const BEID_ReaderSet& reader); /**< Copy not allowed - not implemented */
     BEID_ReaderSet& operator= (const BEID_ReaderSet& reader); /**< Copy not allowed - not implemented */
    
    };
    
    class BEID_Card;
    class BEID_EIDCard;
    class BEID_KidsCard;
    class BEID_ForeignerCard;
    class BEID_SISCard;
    
    /******************************************************************************//**
     * This class represent a reader.
     * You get reader object from the ReaderSet
     * either by its index (getReaderByNum) or by its name (getReaderByName).
     * Once you have a reader object, you can check if a card is present (isCardPresent).
     * Then you can ask which type of card is in the reader with getCardType()
     * and then get a card object using one of this method :
     * getCard, getEIDCard, getKidsCard, getForeignerCard or getSISCard.
     *********************************************************************************/
    class BEID_ReaderContext : public BEID_Object
    {
    public:
     /**
     * Construct using a fileType and fileName.
     * No physical reader are connected (m_reader=NULL)
     */
     BEIDSDK_API BEID_ReaderContext(BEID_FileType fileType,const char *fileName);
    
     /**
     * Construct using a fileType and its content (for compatibility with SetRawFile).
     * No physical reader are connected (m_reader=NULL)
     */
     BEIDSDK_API BEID_ReaderContext(BEID_FileType fileType,const BEID_ByteArray &data);
    
     /**
     * Construct using Raw data for Eid.
     * No physical reader are connected (m_reader=NULL)
     */
     BEIDSDK_API BEID_ReaderContext(const BEID_RawData_Eid &data);
    
     /**
     * Construct using Raw data for Sis.
     * No physical reader are connected (m_reader=NULL)
     */
     BEIDSDK_API BEID_ReaderContext(const BEID_RawData_Sis &data);
    
     BEIDSDK_API virtual ~BEID_ReaderContext(); /**< Destructor */
    
     /**
     * Return the name of the reader.
     */
     BEIDSDK_API const char *getName();
    
     /**
     * Return true if a card is present and false otherwise.
     */
     BEIDSDK_API bool isCardPresent();
    
     /**
     * Release the card.
     *
     * @param bAllReference If true all the invalid reference/pointer are destroyed.
     * @param bAllReference PUT THIS PARAMETER TO TRUE IS THREAD UNSAFE.
     * @param bAllReference You have to be sure that you will not use any old reference/pointer after this release
     */
     BEIDSDK_API void releaseCard(bool bAllReference=false);
    
     /**
     * Return true if a card has changed since the last called (with the same ulOldId parameter).
     */
     BEIDSDK_API bool isCardChanged(unsigned long &ulOldId);
    
     /**
     * Return the type of the card in the reader.
     *
     * Throw BEID_ExNoCardPresent exception if no card is present.
     */
     BEIDSDK_API BEID_CardType getCardType();
    
     /**
     * Get the card in the reader.
     * Instantiation is made regarding the type of the card
     * (BEID_EIDCard, BEID_KidsCard, BEID_ForeignerCard or BEID_SISCard).
     *
     * If no card is present in the reader, exception BEID_ExNoCardPresent is thrown.
     * If the card type is not supported, exception BEID_ExCardTypeUnknown is thrown.
     */
     BEIDSDK_API BEID_Card &getCard();
    
     /**
     * Get the EIDcard in the reader.
     * Instantiation is made regarding the type of the card
     * (BEID_EIDCard, BEID_KidsCard, BEID_ForeignerCard).
     *
     * If no card is present in the reader, exception BEID_ExNoCardPresent is thrown.
     * If the card is not an EIDcard, exception BEID_ExCardBadType is thrown.
     */
     BEIDSDK_API BEID_EIDCard &getEIDCard();
    
     /**
     * Get the KidsCard in the reader.
     *
     * If no card is present in the reader, exception BEID_ExNoCardPresent is thrown.
     * If the card is not a KidsCard, exception BEID_ExCardBadType is thrown.
     */
     BEIDSDK_API BEID_KidsCard &getKidsCard();
    
     /**
     * Get the ForeignerCard in the reader.
     *
     * If no card is present in the reader, exception BEID_ExNoCardPresent is thrown
     * If the card is not a ForeignerCard, exception BEID_ExCardBadType is thrown.
     */
     BEIDSDK_API BEID_ForeignerCard &getForeignerCard();
    
     /**
     * Get the SISCard in the reader.
     *
     * If no card is present in the reader, exception BEID_ExNoCardPresent is thrown.
     * If the card is not a SISCard, exception BEID_ExCardBadType is thrown.
     */
     BEIDSDK_API BEID_SISCard &getSISCard();
    
     /**
     * Specify a callback function to be called each time a
     * card is inserted/remove in/from this reader.
     *
     * @return A handle can be used to stop the callbacks when they are no longer needed.
     */
     BEIDSDK_API unsigned long SetEventCallback(void (* callback)(long lRet, unsigned long ulState, void *pvRef), void *pvRef);
    
     /**
     * To tell that the callbacks are not longer needed.
     * @param ulHandle is the handle return by SetEventCallback
     */
     BEIDSDK_API void StopEventCallback(unsigned long ulHandle);
    
     BEIDSDK_API void BeginTransaction(); /**< Begin a transaction with the reader */
     BEIDSDK_API void EndTransaction(); /**< End the transaction */
    
     BEIDSDK_API bool isVirtualReader(); /**< Return true if this is a virtual reader (create from a file) */
    
    private:
     BEID_ReaderContext(const BEID_ReaderContext& reader); /**< Copy not allowed - not implemented */
     BEID_ReaderContext& operator= (const BEID_ReaderContext& reader); /**< Copy not allowed - not implemented */
    
     BEID_ReaderContext(const SDK_Context *context,APL_ReaderContext *impl); /**< For internal use : Constructor */
    
     unsigned long m_cardid;
     //CMutex *m_mutex;
    
    friend BEID_ReaderContext &BEID_ReaderSet::getReader(APL_ReaderContext *pAplReader); /**< For internal use : This method must access protected constructor */
    };
    
     
  2. 8. April 2011
    AW: LNK2019 - Verweis auf nicht aufgelöstes externes Symbol

    Du musst natürlich auch gegen die .lib oder .dll linken. In der .h steht nur die Deklaration, sprich du in der .h wird dem Compiler nur gesagt, dass eine Funktion/Klasse/Variable existiert und welche Größe sie hat.
    Die Definition steht in der dazugehörigen .cpp Datei (oder halt in der Bibliothek, wenn die .cpp-Datei compiled wurde). Die Definition interessiert den Compiler überhaupt nicht, sondern nur den Linker (deshalb ist die Fehlermeldung da oben vom Linker). Der Linker muss nämlich die Definition wissen, damit er weiß, wohin er bei nem bestimmten Funktionsaufruf springen muss.

    Von daher: Die .lib bei den Linkereigenschaften hinzufügen.
     
  3. 8. April 2011
    AW: LNK2019 - Verweis auf nicht aufgelöstes externes Symbol

    OK, hört sich ja plausibel an, hätte ich auch selber drauf kommen können.
    Aber wo füge ich die Dateien hinzu, habe hier eine DLL und eine LIB.

    Danke dir vielmals
     
  4. 8. April 2011
    AW: LNK2019 - Verweis auf nicht aufgelöstes externes Symbol

    Wer suchet, der findet.

    closed.
     
  5. Video Script

    Videos zum Themenbereich

    * gefundene Videos auf YouTube, anhand der Überschrift.