LNK2019 error in functions with CString& as parameter

I am exporting a class that have few functions with CString& as parameters from a library. When i use this library in other DLL project it gives me the following errors.I am using VC++ 8.0 compiler.

The code is as follows:

class __declspec(dllimport) CRDASvrCommunication::public CRDARegFile
{
//Some variables...
// Other fn decln.
void GetAppIniFilePath(CString&); //Giving problem
}

Same is with other classes having function CString& as parameters.

Errors-

ClientStamp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall CRDASvrCommunication::GetAppIniFilePath(class ATL::CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char> > > &)" (__imp_ GetAppIniFilePath@CRDASvrCommunication@@QAEXAAV $CStringT@DV $StrTraitMFC@DV $ChTraitsCRT@D@ATL@@@@@ATL@@@Z) referenced in function "public: int __thiscall CClientStamp::ProcessCloseStamp(struct _EXTENSION_CONTROL_BLOCK &)" ( ProcessCloseStamp@CClientStamp@@QAEHAAU_EXTENSION_CONTROL_BLOCK@@@Z)
PCTWeb.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __thiscall CAlInifileEx::WriteDuplicateString(class ATL::CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char> > > const &,class ATL::CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char> > > const &,class ATL::CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char> > > const &)" (__imp_ WriteDuplicateString@CAlInifileEx@@QAEHABV $CStringT@DV $StrTraitMFC@DV $ChTraitsCRT@D@ATL@@@@@ATL@@00@Z) referenced in function "int __cdecl DeleteStamp(class ATL::CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char> > >)" ( DeleteStamp@@YAHV $CStringT@DV $StrTraitMFC@DV $ChTraitsCRT@D@ATL@@@@@ATL@@@Z)
PCTWeb.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __thiscall CAlInifileEx::Open(class ATL::CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char> > > const &)" (__imp_ Open@CAlInifileEx@@QAEHABV $CStringT@DV $StrTraitMFC@DV $ChTraitsCRT@D@ATL@@@@@ATL@@@Z) referenced in function "int __cdecl DeleteStamp(class ATL::CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char> > >)" ( DeleteStamp@@YAHV $CStringT@DV $StrTraitMFC@DV $ChTraitsCRT@D@ATL@@@@@ATL@@@Z)
../../Build/Release/Web.dll : fatal error LNK1120: 3 unresolved externals




}


Answer this question

LNK2019 error in functions with CString& as parameter

  • Jacky Zhou

    You need to use __declspec(dllexport) for the class definition built by the DLL project. For the client project, use __declspec(dllimport).

    If you create a DLL project using the New Project wizard, you can see how this is done with a macro.

    Brian


  • Rasheed1979

    You have to do something like this:

    #ifdef DLLBUILD

    #define DLLEXP __declspec(dllexport)

    #else

    #define DLLEXP __declspec(dllimport)

    #endif

    class DLLEXP CRDASvrCommunication : public CRDARegFile
    {
    void GetAppIniFilePath(CString&); //Giving problem
    };

    and then you define DLLBUILD in your DLL project, but not in the client.

    Additionally, I don't think this is the code you actually have, right

    CRDASvrCommunication::public CRDARegFile



  • davef8

    Yeah it is done the same way as you have described but still this error persists.
  • LNK2019 error in functions with CString& as parameter