Firefox NPAPI Xcode link errors

与世无争的帅哥 提交于 2020-01-26 03:35:27

问题


I'm trying to build a Firefox plugin for Mac OSX, it build well but I don't understand why the linker failed.

Here is the log of the linker:

Undefined symbols:
  "_NPN_ReleaseVariantValue", referenced from:
      _NPP_New in npp_gate.o
      _NPP_New in npp_gate.o
  "_NPN_MemAlloc", referenced from:
      String2Variant(_NPVariant*, char const*)in plugin.o
  "_NPN_GetValue", referenced from:
      _NPP_New in npp_gate.o
  "_NPN_ReleaseObject", referenced from:
      CPlugin::~CPlugin()in plugin.o
      CPlugin::~CPlugin()in plugin.o
  "_NPN_Version", referenced from:
      CPlugin::CPlugin(_NPP*)in plugin.o
      CPlugin::CPlugin(_NPP*)in plugin.o
  "_NPN_UserAgent", referenced from:
      CPlugin::CPlugin(_NPP*)in plugin.o
      CPlugin::CPlugin(_NPP*)in plugin.o
  "_NPN_GetProperty", referenced from:
      _NPP_New in npp_gate.o
      _NPP_New in npp_gate.o
  "_NPN_GetURL", referenced from:
      _NPP_New in npp_gate.o
      CPluginData::Fire_OnZoomChange()       in CTPlugin.o
      CPluginData::Fire_OnPIPMove()       in CTPlugin.o
      CPluginData::Fire_OnItem(int, bool)in CTPlugin.o
      CPluginData::Fire_OnClose(char const*)in CTPlugin.o
      CPluginData::Fire_OnWheel(int)    in CTPlugin.o
      CPluginData::Fire_OnRightClick(int, int)in CTPlugin.o
      CPluginData::Fire_OnKeyPress(unsigned short)in CTPlugin.o
      CPluginData::Fire_OnMouseDn(int, int)in CTPlugin.o
      CPluginData::Fire_OnMouseUp(int, int)in CTPlugin.o
      CPluginData::Fire_OnMouseMove(int, int)in CTPlugin.o
      CPluginData::Fire_OnClick(int, int)in CTPlugin.o
      CPluginData::Fire_OnSelect()       in CTPlugin.o
      CPluginData::Fire_OnStatus(char const*)in CTPlugin.o
      CPluginData::Fire_OnImage(int, int, int, int)in CTPlugin.o
  "_NPN_CreateObject", referenced from:
      CPlugin::GetScriptableObject()      in plugin.o
  "_NPN_GetStringIdentifier", referenced from:
      _NPP_New in npp_gate.o
      _NPP_New in npp_gate.o
      CPlugin::CPlugin(_NPP*)in plugin.o
      CPlugin::CPlugin(_NPP*)in plugin.o
      CPlugin::CPlugin(_NPP*)in plugin.o
      CPlugin::CPlugin(_NPP*)in plugin.o
      CPlugin::CPlugin(_NPP*)in plugin.o
      CPlugin::CPlugin(_NPP*)in plugin.o
  "_NPN_InvalidateRect", referenced from:
      CPluginData::Refresh(bool)  in CTPlugin.o
  "_NPN_RetainObject", referenced from:
      CPlugin::GetScriptableObject()      in plugin.o

I really don't understand what I've done bad! Have I missed libraries to link with? Thanks in advance =)

EDIT: Add code example, for the _NPN_MemAlloc from String2Variant in plugin.o:

static void String2Variant(NPVariant *result, LPCTSTR value)
    {
        if (value)
        {
            ClassUnicode cu;
            char *utf8String = cu.CurrentModeToUTF8(value);

            uint32 len = (uint32) strlen(utf8String);
            char *clone = (char *)NPN_MemAlloc(len+1);
            memcpy(clone,utf8String,len);
            clone[len] = '\0';
        } else
        {
            result->type = NPVariantType_String;
            result->value.stringValue.UTF8Characters = NULL;
            result->value.stringValue.UTF8Length = 0;
        }
    }

回答1:


There is no library that provides NPN_MemAlloc, it is actually one of the callbacks that you get when the browser calls NP_Initialize. You need to store the aNPNFuncs parameter so that you can use it later:

static NPNetscapeFuncs *sBrowserFuncs;

NPError NP_Initialize(NPNetscapeFuncs *aNPNFuncs, NPPluginFuncs *aNPPFuncs)
{
   // Sanity checks go here

   sBrowserFuncs = aNPNFuncs;
}

When you need to call NPN_MemAlloc you do it like this:

sBrowserFuncs->memalloc(len+1);

Or you actually define the function NPN_MemAlloc, the way the test plugin does it:

void*
NPN_MemAlloc(uint32_t size)
{
  return sBrowserFuncs->memalloc(size);
}


来源:https://stackoverflow.com/questions/7308036/firefox-npapi-xcode-link-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!