0

This is probably a duplicate, but there are so many LNK2019 questions, I can't read them all. Here's my problem: I'm getting the following error message:

4>ScatterometerView.obj : error LNK2019: unresolved external symbol 
"__declspec(dllimport) public: __thiscall CPGLGraphBitDlgBSDF::CPGLGraphBitDlgBSDF(class CPGLGraph *)" (__imp_??0CPGLGraphBitDlgBSDF@@QAE@PAVCPGLGraph@@@Z) 
referenced in function "public: void __thiscall CScatterometerView::DisplayBSDFPlot(class BSDF *)" (?DisplayBSDFPlot@CScatterometerView@@QAEXPAVBSDF@@@Z)

When I look at the output of DUMPBIN, I see my constructor:

12    B 00002EFF ??0CPGLGraphBitDlgBSDF@@QAE@PAVCPGLGraph@@@Z = @ILT+7930(??0CPGLGraphBitDlgBSDF@@QAE@PAVCPGLGraph@@@Z)

It has everything except the __imp__. The class in the DLL is defined as follows:

#define PGL_EXT_CLASS _declspec(dllexport)
class PGL_EXT_CLASS CPGLGraphBitDlgBSDF : public CPGLGraphDlg
{
public:
    static const int numPointsToAvg = 3;
    CPGLGraphBitDlgBSDF();
    CPGLGraphBitDlgBSDF(CPGLGraph* _pGraph);
    ~CPGLGraphBitDlgBSDF(void);
    // ...lots more functions...
}

and the usage in the executable is:

CPGLGraph* pGraph = new CPGLGraph;
// ...code to fill in the graph data...
m_bsdf_plot = new CPGLGraphBitDlgBSDF(pGraph);

The kicker is that every other function in the class works; only the two I added recently (including this constructor) don't work. The older functions don't have the __imp__ decoration that seems to be required of my newly added functions.

The .def files that were created define no functions, so this doesn't seem to be a difference. I used the MAP file on the linker, and the only functions that have the __imp__ prefix are those defined by Microsoft. Not a single function defined in PGL.dll has it, and they all work fine. Please tell me where to look for the problem or even clues.

valiano
  • 16,433
  • 7
  • 64
  • 79

1 Answers1

0
#pragma once
#if defined DLL_EXPORT
#define MY_API_NAME __declspec(dllexport)
#else
#define MY_API_NAME __declspec(dllimport)
#endif

Normally that stands in your .hpp from your DLL. You need to define DLL_EXPORT in the preprocessor settings from the DLL project, so the functions will be exported when building the DLL and imported, when it is used in a different project.

Ajay
  • 18,086
  • 12
  • 59
  • 105
Hannes Hauptmann
  • 324
  • 2
  • 14
  • Good point. My code is based on PGL (Plot Graphics Library), and code almost exactly like yours already exists in PGL.h, which is #included in my file. Any other ideas? – Steve Eckhardt Jun 10 '16 at 19:16
  • I am not sure, but try to export the functions of the class all manually. Like write your PGL_EXT_CLASS in front of the constructor/destructor/functions. Maybe there is something in the class wich cant be exported, happened to me a time ago. – Hannes Hauptmann Jun 10 '16 at 19:59
  • Another good idea! Unfortunately, when I tried it I got the following error message: "A member of a class declared with dllexport/dllimport cannot itself be declared with such a specifier". So it is now certain that the class is declared with dllexport and that I cannot employ your latest suggestion. At least I learned something. – Steve Eckhardt Jun 10 '16 at 20:41
  • When you export the functions manually, you must remove PGL_EXT_GLASS in `class PGL_EXT_CLASS CPGLGraphBitDlgBSDF` my fault :) – Hannes Hauptmann Jun 10 '16 at 20:46