LNK 2001在NPPluginFuncs struct ptr上未解析外部作为静态类成员

时间:2014-02-23 19:27:33

标签: c++ struct npapi lnk2001

在我的VS2010 DLL项目中,编译此项目时出错:LNK 2001在我班级的pFuncs成员中未解析外部:

class Foo
{
    // ...
    static NPPluginFuncs * pFuncs;
    // ...
};

这是一个结构,在 npfunctions.h

中定义
typedef struct _NPPluginFuncs {
  uint16_t size;
  uint16_t version;
  NPP_NewProcPtr newp;
  NPP_DestroyProcPtr destroy;
  NPP_SetWindowProcPtr setwindow;
  NPP_NewStreamProcPtr newstream;
  NPP_DestroyStreamProcPtr destroystream;
  NPP_StreamAsFileProcPtr asfile;
  NPP_WriteReadyProcPtr writeready;
  NPP_WriteProcPtr write;
  NPP_PrintProcPtr print;
  NPP_HandleEventProcPtr event;
  NPP_URLNotifyProcPtr urlnotify;
  void* javaClass;
  NPP_GetValueProcPtr getvalue;
  NPP_SetValueProcPtr setvalue;
  NPP_GotFocusPtr gotfocus;
  NPP_LostFocusPtr lostfocus;
  NPP_URLRedirectNotifyPtr urlredirectnotify;
  NPP_ClearSiteDataPtr clearsitedata;
  NPP_GetSitesWithDataPtr getsiteswithdata;
  NPP_DidCompositePtr didComposite;
} NPPluginFuncs;

1 个答案:

答案 0 :(得分:2)

结构(或类)的静态成员在typedef struct { };中声明,需要明确定义一次:

#include "npfunctions.h"

Foo::pFuncs = NULL;  // optional initialization


int main()
{
    Foo::pFuncs = new NPPluginFuncs;
}