Link error LNK2001 while using CView derivative in a DLL 
Author Message
 Link error LNK2001 while using CView derivative in a DLL

We have a such situation:

1.----------------------------
DllFile.h:
    class AFX_EXT_CLASS CGUIFlexGridView : public CView
    {
        protected:
             CGUIFlexGridView();
             DECLARE_DYNCREATE(CGUIFlexGridView)
     ...

DllFile.cpp:
    IMPLEMENT_DYNCREATE(CGUIFlexGridView, CView)

DllFile.dll compiles and links successfully.

2.--------------------------
ExeFile.h:
    class CKMView : public CGUIFlexGridView
    {
        protected:
             CKMView();
             DECLARE_DYNCREATE(CKMView)
    ...

ExeFile.cpp:
    IMPLEMENT_DYNCREATE(CKMView, CGUIFlexGridView)

The ExeFile project  is using the DllFile.lib. The compiling is OK. Linking,
however, fails with error:
--------------------------------------------------------------
error LNK2001: unresolved external symbol
"public: static struct CRuntimeClass const
CGUIFlexGridView::classCGUIFlexGridView"

ExeFile.exe : fatal error LNK1120: 1 unresolved externals
--------------------------------------------------------------

Looks like the structure defined by IMPLEMENT_DYNCREATE(CGUIFlexGridView,
CView) is not exported/imported properly.
What is the problem and how to resolve it?

The similar problem happens while linking to classes with a message map
defined.

Yours DW.



Tue, 26 Oct 2004 21:29:06 GMT  
 Link error LNK2001 while using CView derivative in a DLL
I see you are using AFX_EXT_CLASS to do your export/import declaration.  
Do you have more than one DLL layer in your application?  Is it possible
that AFX_EXT_CLASS is not being properly translated to __declspec
(dllimport)?


Wed, 27 Oct 2004 10:57:42 GMT  
 Link error LNK2001 while using CView derivative in a DLL

Quote:
> I see you are using AFX_EXT_CLASS to do your export/import declaration.

Yes. It is in the source.

Quote:
> Do you have more than one DLL layer in your application?  Is it possible
> that AFX_EXT_CLASS is not being properly translated to __declspec
> (dllimport)?

In fact, I did not tell the whole truth (I wanted to simplify, but it looks
I oversimplified the case). The Dll class is not used as a base class for a
class in an exe file (as I wrote in the first post). The derivative is
inside another dll file. I think THIS is the case. Probably, exactly as you
wrote, the AFX_EXT_CLASS is not properly translated in all cases. I tried
various #undefs and #defines, but with no results yet. I do not know, wat
else to try. Have you ever had such a situation and worked out a solution?

Yours DW.



Fri, 29 Oct 2004 14:42:18 GMT  
 Link error LNK2001 while using CView derivative in a DLL
In fact, I did not tell the whole truth (I wanted to simplify, but it looks
I oversimplified the case). The Dll class is not used as a base class for a
class in an exe file (as I wrote in the first post). The derivative is
inside another dll file. I think THIS is the case. Probably the
AFX_EXT_CLASS is not properly translated to __declspec(dllimport). I tried
various #undefs and #defines, but with no results yet. I do not know, what
else to try. Have you ever had such a situation and worked out any solution?

Yours DW.



Fri, 29 Oct 2004 15:03:51 GMT  
 Link error LNK2001 while using CView derivative in a DLL


Wed, 18 Jun 1902 08:00:00 GMT  
 Link error LNK2001 while using CView derivative in a DLL
In the header of the derived class, we wrote something like this:

--------------------------------------------------------------------
#undef AFX_EXT_CLASS
#undef AFX_EXT_API
#undef AFX_EXT_DATA
#define AFX_EXT_CLASS       AFX_CLASS_IMPORT
#define AFX_EXT_API         AFX_API_IMPORT
#define AFX_EXT_DATA        AFX_DATA_IMPORT

  #include "..\Globals\GUIFlexGridView.h"

#undef AFX_EXT_CLASS
#undef AFX_EXT_API
#undef AFX_EXT_DATA
#define AFX_EXT_CLASS       AFX_CLASS_EXPORT
#define AFX_EXT_API         AFX_API_EXPORT
#define AFX_EXT_DATA        AFX_DATA_EXPORT

--------------------------------------------------------------------

It works. Is it a good workaround? Is there any risk of something
unpredicted?

Yours DW.



Fri, 29 Oct 2004 18:17:49 GMT  
 Link error LNK2001 while using CView derivative in a DLL
DW,
    I think your workaround is unnecessarily complex and obscure.  When
using multiple DLLs, especially when they are nested like this, do not
use the AFX_EXT_CLASS macro at all.  Instead, just define your own
macros, one for each DLL.  (I have done this dozens of times, so I'm
sure it will work.)  As an example, in the header for exports from a DLL
named "First.DLL", have #defines like this:

#ifdef _FIRSTDLL_LOCAL
#define FIRSTDLL_EXPORT __declspec(dllexport)
#else
#define FIRSTDLL_EXPORT __declspec(dllimport)
#endif

For "Second.DLL", have this:

#ifdef _SECONDDLL_LOCAL
#define SECONDDLL_EXPORT __declspec(dllexport)
#else
#define SECONDDLL_EXPORT __declspec(dllimport)
#endif

In the project that creates First.DLL, define _FIRSTDLL_LOCAL.  In
Second.DLL's project, define _SECONDDLL_LOCAL.  This way, when building
the DLLs, the symbols will be exported, but when #including the header
from another project, they will be imported.



Fri, 29 Oct 2004 20:41:37 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Link error using GetFileVersionInfoSize() (LNK2001)

2. Linking error LNK2001 when using template classes

3. Error during linking - error LNK2001

4. LNK2001 when trying to link a MFC Extension DLL into another Extension DLL

5. Linking Error LNK2001

6. LNK2001 Linking Error

7. Linking Problem when trying to create ReleaseUMinDependency[error LNK2001: unresolved external symbol _main]

8. Link Error LNK2001: Multithreaded ATL Object

9. Link error LNK2001

10. linking error LNK2001 on DllGetClassObject

11. "error LNK2001" when linking

12. Linking Error when using a static variable from a DLL

 

 
Powered by phpBB® Forum Software