c++ - 构建 XPCOM XULRunner 2.0 或更新版本

标签 c++ mozilla xpcom xulrunner gecko

跟进以下问题:

What lib in the gecko 1.9.3 SDK do I link against to use moz_xmalloc()?

nsIGenericFactory.h is missing in the above version of xulrunner-2.0.en-US.win32.sdk

我能够使用 XULRunner 1.9.2 成功构建 XPCOM。

当我尝试迁移到下一个版本的 XULRunner (> 1.9) 时,我遇到了很多困难。我收到如下链接错误

xpcomglue_s.lib(GenericFactory.obj) : error LNK2001: unresolved external symbol __imp__moz_xmalloc
xpcomglue_s.lib(nsCRTGlue.obj) : error LNK2001: unresolved external symbol __imp__moz_xmalloc
xpcomglue_s.lib(nsTArray.obj) : error LNK2001: unresolved external symbol __imp__moz_xmalloc
xpcomglue_s.lib(nsComponentManagerUtils.obj) : error LNK2001: unresolved external symbol __imp__moz_xmalloc
xpcomglue_s.lib(GenericModule.obj) : error LNK2001: unresolved external symbol __imp__moz_xmalloc
xpcomglue_s.lib(nsISupportsImpl.obj) : error LNK2001: unresolved external symbol __imp__moz_xmalloc

我没有得到明确的迁移步骤以支持当前的 FireFox。

我尝试了链接中提到的建议。我无法解决它。请帮我解决这个问题

最佳答案

我希望有人能提供一份完整的列表,列出应该更改的内容以使其在以后的 gecko 上运行,但由于没有人这样做,我会尝试自己做,使用 this我刚找到的样本。

xpidl.exe

我不知道这是否已经改变,所以这可能不是必需的。 Gecko 11 中没有 xpidl.exe。来自 Philip Chee

的解决方案

It has been replaced by a Python script. You can continue using the XPIDL from the Gecko 7.0 SDK, or compile it from source, or use the Python script.

Gecko 7.0 可以从 ftp 下载 HERE .它确实有 xpidl.exe。用法与 example 中的相同

组件模块实现

这个好像变了很多。 Reference in MDNanother reference (这可以追溯到顶部提供的示例,但解释了一些内容)。

Note that nsIGenericFactory.h has been removed. References to nsIGenericFactory.h should be replaced with mozilla/ModuleUtils.h

在示例项目中还添加了#include "nsIClassInfoImpl.h"

现在最大的一步是更改 NS_IMPL_NSGETMODULE(也被删除),以及 components 的声明,它被用于整组在 sample module 中找到的东西.您可以使用 components 的声明作为引用,我这样做了,有点帮助。

该示例中您唯一不需要的是 kSampleCategories 的声明和用法。只需将其替换为 NULL。至少那是 Benjamin Smedberg said .

常量 kNS_SAMPLE_CID 应替换为 kYOUR_CID_CONSTANT。只需在您的 CID 常量名称前加上 k。

最后一行:

NS_IMPL_MOZILLA192_NSGETMODULE(&kSampleModule)

只需要与 Gecko 1.9 兼容。由于 firefox 3.5 使用它,我想我会离开它。

组件实现(CompImpl.cpp)

引用自sample .

  • 添加 NS_IMPL_CLASSINFO... 行(在示例中是第 80 行)
  • NS_IMPL_ISUPPORTS1 替换为 NS_IMPL_ISUPPORTS1_CI

在这个示例中有很多关于如何使用输入/输出值的好例子。如果你想使用 char* 你还需要使用 nsMemory。我认为对于 nsStrings 这不是必需的。

XPCOM Glue without mozalloc

我们又来了,一堆指向 __imp__moz_xmalloc 的链接错误。这篇很难找到的小文章帮助摆脱了它们:

Starting with XULRunner 2.0, the frozen linkage dependent glue (xpcomglue_s.lib on Windows, libxpcomglue_s.a on Linux and Mac) is dependent on the new infallible memory allocation routines (mozalloc). Since these routines didn't exist prior to XULRunner 2.0, XPCOM components that link against the frozen linkage dependent glue will not be compatible with XULRunner applications prior to 2.0.

The solution is to link against xpcomglue_s_nomozalloc instead (xpcomglue_s_nomozalloc.lib on Windows, libxpcomglue_s_nomozalloc.a on Linux and Mac). This library is new in XULRunner 2.0, and it's identical to xpcomglue_s, except that it's compiled without mozalloc. Simply change all references to "xpcomglue_s" in your compiler and linker flags to "xpcomglue_s_nomozalloc". Resulting XPCOM components will no longer have a dependency on mozalloc, and will thus be compatible with XULRunner applications prior to 2.0 as well.

Comment: You might also need to build your component with the MOZ_NO_MOZALLOC flag (-DMOZ_NO_MOZALLOC)

终于没有报错了

关于c++ - 构建 XPCOM XULRunner 2.0 或更新版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8724997/

相关文章:

c++ - Visual Studio 2010 中的源目录

c++ - 访问 ELF 中的特定部分

javascript - SVG 图像未在 Mozilla 浏览器的 Canvas 中加载

javascript - 获取选项卡的 nsIDOMWindow 进行文本输入

delphi - 将mozilla的NSModule移植到Delphi

c++ - 调用成员函数时更改此指针

javascript - 为什么 mozilla 在嵌入 html 代码时要求插件

firefox - 非 IE 浏览器的浏览器缓存 API

javascript - 帮我创建一个 Firefox 扩展(Javascript XPCOM 组件)

c++ - 接口(interface)上的 Release 调用是否确保 COM 组件被销毁